diff --git a/Assets/Plugins.meta b/Assets/Plugins.meta new file mode 100644 index 0000000..1ad80db --- /dev/null +++ b/Assets/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7b2a329340dffb344a08d395bbb760bd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader.meta b/Assets/Plugins/AllIn13DShader.meta new file mode 100644 index 0000000..0ab47b3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a985c5982fd34304b91e7fcef5a7c64f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig.meta new file mode 100644 index 0000000..bf06126 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1c2677789aedba1449c2462ab739503f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/EffectsProfileCollection.asset b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/EffectsProfileCollection.asset new file mode 100644 index 0000000..54763f0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/EffectsProfileCollection.asset @@ -0,0 +1,454 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e9adb408486385f4db34ebf41514603e, type: 3} + m_Name: EffectsProfileCollection + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.EffectsProfileCollection + generalProfile: + id: + profileName: + shaderGUID: + groups: + - effectGroupConfig: {fileID: 11400000, guid: 05a6bce58cfc83a4293b054fcfc62a81, type: 2} + entries: + - effectID: LIGHTMODEL + displayName: Light Model + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: SHADINGMODEL + displayName: Shading Model + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: + - propertyName: + isEnabled: 0 + keyword: _METALLIC_MAP_ON + displayName: Use Metallic(R) / Smoothness(A) Map? + - effectID: SPECULARMODEL + displayName: Specular Model + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: REFLECTIONS + displayName: Reflections + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: NORMAL_MAP + displayName: Normal Map + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: FLAT_NORMALS + displayName: Flat Normals + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: CUSTOM_SHADOW_COLOR + displayName: Custom Shadow Color + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: AFFECTED_BY_LIGHTMAPS + displayName: Affected by lightmaps + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: + - propertyName: + isEnabled: 0 + keyword: _LIGHTMAP_COLOR_CORRECTION_ON + displayName: Lightmap Color Correction? + - effectID: CUSTOM_AMBIENT_LIGHT + displayName: Custom Ambient Light + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: CAST_SHADOWS_ON + displayName: Cast Shadows + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: RECEIVE_SHADOWS + displayName: Receive Shadows + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: + - propertyName: _ReceivedShadowsType + kwIndexEnabled: 0 + displayNames: + - Classic + - Stylized + keywords: + - _RECEIVEDSHADOWSTYPE_CLASSIC + - _RECEIVEDSHADOWSTYPE_STYLIZED + subkeywordEntriesToggle: [] + - effectGroupConfig: {fileID: 11400000, guid: fcdc7c904b0215f4aabfa8ced0068841, type: 2} + entries: + - effectID: COLOR_RAMP + displayName: Color Ramp + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: + - propertyName: _ColorRampLightingStage + kwIndexEnabled: 0 + displayNames: + - BeforeLighting + - AfterLighting + keywords: + - _COLORRAMPLIGHTINGSTAGE_BEFORELIGHTING + - _COLORRAMPLIGHTINGSTAGE_AFTERLIGHTING + subkeywordEntriesToggle: [] + - effectID: AOMAP + displayName: AO Map + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: HIGHLIGHTS + displayName: Highlights + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: RIM_LIGHTING + displayName: Rim or Fresnel + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: + - propertyName: _RimLightingStage + kwIndexEnabled: 0 + displayNames: + - BeforeLighting + - BeforeLightingLast + - AfterLighting + keywords: + - _RIMLIGHTINGSTAGE_BEFORELIGHTING + - _RIMLIGHTINGSTAGE_BEFORELIGHTINGLAST + - _RIMLIGHTINGSTAGE_AFTERLIGHTING + subkeywordEntriesToggle: [] + - effectID: GREYSCALE + displayName: Greyscale + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: + - propertyName: _GreyScaleStage + kwIndexEnabled: 0 + displayNames: + - BeforeLighting + - AfterLighting + keywords: + - _GREYSCALESTAGE_BEFORELIGHTING + - _GREYSCALESTAGE_AFTERLIGHTING + subkeywordEntriesToggle: [] + - effectID: POSTERIZE + displayName: Posterize + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: HUE_SHIFT + displayName: Hue Shift + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: EMISSION + displayName: Emission + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: HOLOGRAM + displayName: Hologram + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: MATCAP + displayName: Matcap + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: + - propertyName: _MatcapBlendMode + kwIndexEnabled: 0 + displayNames: + - Multiply + - Replace + keywords: + - _MATCAPBLENDMODE_MULTIPLY + - _MATCAPBLENDMODE_REPLACE + subkeywordEntriesToggle: [] + - effectID: HIT + displayName: Hit + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: CONTRAST_BRIGHTNESS + displayName: Contrast and Brightness + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: HEIGHT_GRADIENT + displayName: Height Gradient + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: + - propertyName: _HeightGradientPositionSpace + kwIndexEnabled: 0 + displayNames: + - Local + - World + keywords: + - _HEIGHTGRADIENTPOSITIONSPACE_LOCAL + - _HEIGHTGRADIENTPOSITIONSPACE_WORLD + subkeywordEntriesToggle: [] + - effectID: INTERSECTION_GLOW + displayName: Intersection Glow + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: ALBEDO_VERTEX_COLOR + displayName: Albedo From Vertex Color + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: + - propertyName: _AlbedoVertexColorMode + kwIndexEnabled: 0 + displayNames: + - Multiply + - Replace + keywords: + - _ALBEDOVERTEXCOLORMODE_MULTIPLY + - _ALBEDOVERTEXCOLORMODE_REPLACE + subkeywordEntriesToggle: [] + - effectID: TRIPLANAR_MAPPING + displayName: Triplanar Mapping + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: + - propertyName: _TriplanarNormalSpace + kwIndexEnabled: 0 + displayNames: + - Local + - World + keywords: + - _TRIPLANARNORMALSPACE_LOCAL + - _TRIPLANARNORMALSPACE_WORLD + subkeywordEntriesToggle: + - propertyName: + isEnabled: 0 + keyword: _TRIPLANAR_NOISE_TRANSITION_ON + displayName: Noise Transition + - effectID: TEXTURE_BLENDING + displayName: Texture Blending + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: + - propertyName: _TextureBlendingSource + kwIndexEnabled: 0 + displayNames: + - VertexColor + - Texture + keywords: + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + - _TEXTUREBLENDINGSOURCE_TEXTURE + - propertyName: _TextureBlendingMode + kwIndexEnabled: 0 + displayNames: + - RGB + - BlackAndWhite + keywords: + - _TEXTUREBLENDINGMODE_RGB + - _TEXTUREBLENDINGMODE_BLACKANDWHITE + subkeywordEntriesToggle: [] + - effectID: DEPTH_COLORING + displayName: Depth Coloring + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: SUBSURFACE_SCATTERING + displayName: Fake Subsurface Scattering + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectGroupConfig: {fileID: 11400000, guid: d45649322d809684a8f280736df5ebc7, type: 2} + entries: + - effectID: ALPHA_CUTOFF + displayName: Alpha Cutoff + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: FADE + displayName: Fade + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: + - propertyName: _FadeUVSet + kwIndexEnabled: 0 + displayNames: + - UV1 + - UV2 + - WORLD_SPACE + keywords: + - _FADEUVSET_UV1 + - _FADEUVSET_UV2 + - _FADEUVSET_WORLD_SPACE + subkeywordEntriesToggle: + - propertyName: + isEnabled: 0 + keyword: _FADE_BURN_ON + displayName: Use Fade Burn Color? + - effectID: INTERSECTION_FADE + displayName: Intersection Fade + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: ALPHA_ROUND + displayName: Alpha Round + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: FADE_BY_CAM_DISTANCE + displayName: Fade By Cam Distance + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: + - propertyName: + isEnabled: 0 + keyword: _FADE_BY_CAM_DISTANCE_NEAR_FADE + displayName: Near Fade + - effectID: DITHER + displayName: Dither + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectGroupConfig: {fileID: 11400000, guid: 987f969d8d3fec24bbb35df7779ba52b, type: 2} + entries: + - effectID: VERTEX_SHAKE + displayName: Vertex Shake + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: VERTEX_INFLATE + displayName: Vertex Inflate + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: VERTEX_DISTORTION + displayName: Vertex Distortion + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: VOXELIZE + displayName: Voxelize + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: GLITCH + displayName: Glitch + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: RECALCULATE_NORMALS + displayName: Recalculate Normals + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: WIND + displayName: Wind + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: + - propertyName: + isEnabled: 0 + keyword: _USE_WIND_VERTICAL_MASK + displayName: Use Vertical Mask? + - effectGroupConfig: {fileID: 11400000, guid: 2f3fcb0996a83b64599ce17553aa6b13, type: 2} + entries: + - effectID: SCROLL_TEXTURE + displayName: Scroll Texture + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: SCREEN_SPACE_UV + displayName: Screen Space UV + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: PIXELATE + displayName: Pixelate + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: STOCHASTIC_SAMPLING + displayName: Stochastic Sampling + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: WAVE_UV + displayName: Wave UV On + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: HAND_DRAWN + displayName: Hand Drawn + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectID: UV_DISTORTION + displayName: Distortion + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + - effectGroupConfig: {fileID: 11400000, guid: d29aa9c55e3576d4bad55ec71545fe82, type: 2} + entries: + - effectID: OUTLINETYPE + displayName: Outline Type + isEnabled: 1 + kwEnabledIndex: 0 + subkeywordEntriesEnum: [] + subkeywordEntriesToggle: [] + profiles: [] diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/EffectsProfileCollection.asset.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/EffectsProfileCollection.asset.meta new file mode 100644 index 0000000..bd3e852 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/EffectsProfileCollection.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 338be309f1396204884361d9bcd1dde1 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export.meta new file mode 100644 index 0000000..c9716a0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b4f20d402f36d7541bc02c148de29092 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Atlases.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Atlases.meta new file mode 100644 index 0000000..37e40e8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Atlases.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b200bc2717fdb924b8146e41ffb099a0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Baked Shaders.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Baked Shaders.meta new file mode 100644 index 0000000..dd20db6 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Baked Shaders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8d5ea0b6ac98f1342803ac5a9c4bae6e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Gradients.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Gradients.meta new file mode 100644 index 0000000..0cb41c9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Gradients.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bcd13420d4726c7468cc144daea0974d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Images.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Images.meta new file mode 100644 index 0000000..17f5c9b --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Images.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 54669f4ed8a497a4aa02326c998cfe96 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Materials.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Materials.meta new file mode 100644 index 0000000..c1a8208 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Materials.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2aebb80a8c8823d4fb6931bf98c49e17 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Noises.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Noises.meta new file mode 100644 index 0000000..d127444 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Noises.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4f8f01dc480b3c84d8736e559f2e8bc1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Normal Maps.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Normal Maps.meta new file mode 100644 index 0000000..cc8a817 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/Export/Normal Maps.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0e04a0b45280046418f226a943d19ae8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/GlobalConfiguration.asset b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/GlobalConfiguration.asset new file mode 100644 index 0000000..82abf57 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/GlobalConfiguration.asset @@ -0,0 +1,43 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 592122c0ab3d6c04d85891bcd2f332bc, type: 3} + m_Name: GlobalConfiguration + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.GlobalConfiguration + projectType: 2 + standardBasicMaterial: {fileID: 2100000, guid: 1df0aef2ca6d85a4b9bb7478096c635a, type: 2} + standardPBRMaterial: {fileID: 2100000, guid: fed1698affe6c124c8eece7c36b256f0, type: 2} + toonMaterial: {fileID: 2100000, guid: deae43ec6cafe38498ce343202e24586, type: 2} + allIn13dDShaderLookMaterial: {fileID: 2100000, guid: c47ffb1264d98194ca46e4502b86c74f, type: 2} + defaultPreset: {fileID: 2100000, guid: fed1698affe6c124c8eece7c36b256f0, type: 2} + rootPluginPath: Assets\Plugins\AllIn13DShader + globalConfigFolderPath: Assets\Plugins\AllIn13DShader\AllIn3DShaderConfig + exportFolderPath: Assets\Plugins\AllIn13DShader\AllIn3DShaderConfig\Export + materialSavePath: Assets\Plugins\AllIn13DShader\AllIn3DShaderConfig\Export\Materials + renderImageSavePath: Assets\Plugins\AllIn13DShader\AllIn3DShaderConfig\Export\Images + normalMapSavePath: Assets\Plugins\AllIn13DShader\AllIn3DShaderConfig\Export\Normal + Maps + gradientSavePath: Assets\Plugins\AllIn13DShader\AllIn3DShaderConfig\Export\Gradients + atlasesSavePath: Assets\Plugins\AllIn13DShader\AllIn3DShaderConfig\Export\Atlases + noiseSavePath: Assets\Plugins\AllIn13DShader\AllIn3DShaderConfig\Export\Noises + bakedShaderSavePath: Assets\Plugins\AllIn13DShader\AllIn3DShaderConfig\Export\Baked + Shaders + renderImageScale: 0 + projectConfiguredFirstTime: 1 + urpConfiguredFirstTime: 1 + lastPipelineConfiguredGUID: + shStandard: {fileID: 4800000, guid: 0dde7f0097aeb2541aea684ca0ad0e3c, type: 3} + shStandardNoShadowCaster: {fileID: 4800000, guid: 3bc39c06ce1e4fb44bc21dcf24dde7fe, type: 3} + shOutline: {fileID: 4800000, guid: a4c8f68acf7c9844e97a36914026acb1, type: 3} + shOutlineNoShadowCaster: {fileID: 4800000, guid: 7fd6f68952c76af4c8005466df606651, type: 3} + effectsProfileCollection: {fileID: 11400000, guid: 338be309f1396204884361d9bcd1dde1, type: 2} + shaderPassCollection: {fileID: 11400000, guid: 02697d53e5a592b43b0b78710cd1fd60, type: 2} + urpSettingsUserPref: {fileID: 11400000, guid: 132a4a2cab34542418073815edcd22de, type: 2} diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/GlobalConfiguration.asset.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/GlobalConfiguration.asset.meta new file mode 100644 index 0000000..5d58754 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/GlobalConfiguration.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b44e2d895bc689043a9fb62a9b4b5b3d +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/PropertiesConfigCollection.asset b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/PropertiesConfigCollection.asset new file mode 100644 index 0000000..24a01a1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/PropertiesConfigCollection.asset @@ -0,0 +1,8046 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: de2c732907004674f91e71073a09d404, type: 3} + m_Name: PropertiesConfigCollection + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.PropertiesConfigCollection + propertiesConfig: + shader: {fileID: 4800000, guid: a4c8f68acf7c9844e97a36914026acb1, type: 3} + effectsGroups: + - effectGroupConfig: {fileID: 11400000, guid: 05a6bce58cfc83a4293b054fcfc62a81, type: 2} + effects: + - effectName: LIGHTMODEL + displayName: Light Model + group: Lighting + keywordPropertyIndex: 21 + keywordPropertyName: _LightModel + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/fast-lighting + customMessages: + - message: "*You need to use FastLightConfigurator.cs component\n in order + to use this effect." + keywords: + - _LIGHTMODEL_FASTLIGHTING + keywords: + - keyword: _LIGHTMODEL_NONE + displayName: None + - keyword: _LIGHTMODEL_CLASSIC + displayName: Classic + - keyword: _LIGHTMODEL_TOON + displayName: Toon + - keyword: _LIGHTMODEL_TOONRAMP + displayName: ToonRamp + - keyword: _LIGHTMODEL_HALFLAMBERT + displayName: HalfLambert + - keyword: _LIGHTMODEL_FAKEGI + displayName: FakeGI + - keyword: _LIGHTMODEL_FASTLIGHTING + displayName: FastLighting + keywordsDisplayNames: + - None + - Classic + - Toon + - ToonRamp + - HalfLambert + - FakeGI + - FastLighting + effectProperties: + - parentEffect: + rid: 6567500035957719294 + propertyIndex: 22 + propertyName: _ToonCutoff + displayName: Toon Cutoff + keywords: + - _LIGHTMODEL_TOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719294 + propertyIndex: 23 + propertyName: _ToonSmoothness + displayName: Toon Smoothness + keywords: + - _LIGHTMODEL_TOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719294 + propertyIndex: 24 + propertyName: _ToonRamp + displayName: Toon Ramp + keywords: + - _LIGHTMODEL_TOONRAMP + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719294 + propertyIndex: 25 + propertyName: _HalfLambertWrap + displayName: Half Lambert + keywords: + - _LIGHTMODEL_HALFLAMBERT + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719294 + propertyIndex: 26 + propertyName: _HardnessFakeGI + displayName: Fake GI Hardness + keywords: + - _LIGHTMODEL_FAKEGI + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 1 + effectConfigType: 1 + extraPasses: 06000000 + - effectName: SHADINGMODEL + displayName: Shading Model + group: Lighting + keywordPropertyIndex: 27 + keywordPropertyName: _ShadingModel + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: LIGHTMODEL + incompatibleWithEffectID: + docURL: + customMessages: + - message: '*Usually looks best paired with a Specular Model' + keywords: + - _SHADINGMODEL_PBR + keywords: + - keyword: _SHADINGMODEL_BASIC + displayName: Basic + - keyword: _SHADINGMODEL_PBR + displayName: PBR + keywordsDisplayNames: + - Basic + - PBR + effectProperties: + - parentEffect: + rid: 6567500035957719295 + propertyIndex: 28 + propertyName: _Metallic + displayName: Metallic + keywords: + - _SHADINGMODEL_PBR + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719295 + propertyIndex: 29 + propertyName: _Smoothness + displayName: Smoothness + keywords: + - _SHADINGMODEL_PBR + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719295 + propertyIndex: 30 + propertyName: _MetallicMapOn + displayName: Use Metallic(R) / Smoothness(A) Map? + keywords: + - _SHADINGMODEL_PBR + incompatibleKeywords: + - + propertyKeywords: + - _METALLIC_MAP_ON + fullKeywordNames: + - _METALLIC_MAP_ON + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719295 + propertyIndex: 31 + propertyName: _MetallicMap + displayName: Metallic Map + keywords: + - _SHADINGMODEL_PBR + - _METALLIC_MAP_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 1 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + disabledKeyword: + displayIndex: 2 + effectConfigType: 1 + extraPasses: + - effectName: SPECULARMODEL + displayName: Specular Model + group: Lighting + keywordPropertyIndex: 32 + keywordPropertyName: _SpecularModel + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: LIGHTMODEL + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _SPECULARMODEL_NONE + displayName: None + - keyword: _SPECULARMODEL_CLASSIC + displayName: Classic + - keyword: _SPECULARMODEL_TOON + displayName: Toon + - keyword: _SPECULARMODEL_ANISOTROPIC + displayName: Anisotropic + - keyword: _SPECULARMODEL_ANISOTROPICTOON + displayName: AnisotropicToon + keywordsDisplayNames: + - None + - Classic + - Toon + - Anisotropic + - AnisotropicToon + effectProperties: + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 33 + propertyName: _SpecularAtten + displayName: Specular Attenuation + keywords: + - _SPECULARMODEL_CLASSIC + - _SPECULARMODEL_TOON + - _SPECULARMODEL_ANISOTROPIC + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 34 + propertyName: _Shininess + displayName: Shininess + keywords: + - _SPECULARMODEL_CLASSIC + - _SPECULARMODEL_TOON + incompatibleKeywords: + - _SHADINGMODEL_PBR + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 35 + propertyName: _AnisoShininess + displayName: Aniso Shininess + keywords: + - _SPECULARMODEL_ANISOTROPIC + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: + - _SHADINGMODEL_PBR + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 36 + propertyName: _SpecularToonCutoff + displayName: Specular Toon Cutoff + keywords: + - _SPECULARMODEL_TOON + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 37 + propertyName: _SpecularToonSmoothness + displayName: Specular Toon Smoothness + keywords: + - _SPECULARMODEL_TOON + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 38 + propertyName: _SpecularMap + displayName: Specular Map + keywords: + - _SPECULARMODEL_CLASSIC + - _SPECULARMODEL_TOON + - _SPECULARMODEL_ANISOTROPIC + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 39 + propertyName: _Anisotropy + displayName: Anisotropy + keywords: + - _SPECULARMODEL_ANISOTROPIC + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 3 + effectConfigType: 1 + extraPasses: + - effectName: REFLECTIONS + displayName: Reflections + group: Lighting + keywordPropertyIndex: 40 + keywordPropertyName: _Reflections + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: LIGHTMODEL + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _REFLECTIONS_NONE + displayName: None + - keyword: _REFLECTIONS_CLASSIC + displayName: Classic + - keyword: _REFLECTIONS_TOON + displayName: Toon + keywordsDisplayNames: + - None + - Classic + - Toon + effectProperties: + - parentEffect: + rid: 6567500035957719297 + propertyIndex: 41 + propertyName: _ToonFactor + displayName: Toon Factor + keywords: + - _REFLECTIONS_TOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719297 + propertyIndex: 42 + propertyName: _ReflectionsAtten + displayName: Attenuation + keywords: + - _REFLECTIONS_CLASSIC + - _REFLECTIONS_TOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 4 + effectConfigType: 1 + extraPasses: + - effectName: NORMAL_MAP + displayName: Normal Map + group: Lighting + keywordPropertyIndex: 43 + keywordPropertyName: _NormalMapEnabled + effectDrawerID: NORMAL_MAP_EFFECT_DRAWER + dependentOnEffect: LIGHTMODEL + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _NORMAL_MAP_ON + displayName: _NORMAL_MAP_ON + keywordsDisplayNames: + - _NORMAL_MAP_ON + effectProperties: + - parentEffect: + rid: 6567500035957719298 + propertyIndex: 44 + propertyName: _NormalMap + displayName: Normal Map + keywords: + - _NORMAL_MAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719298 + propertyIndex: 45 + propertyName: _NormalStrength + displayName: Normal Strength + keywords: + - _NORMAL_MAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 5 + effectConfigType: 0 + extraPasses: + - effectName: FLAT_NORMALS + displayName: Flat Normals + group: Lighting + keywordPropertyIndex: 46 + keywordPropertyName: _FlatNormalsEnabled + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: LIGHTMODEL + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _FLAT_NORMALS_ON + displayName: _FLAT_NORMALS_ON + keywordsDisplayNames: + - _FLAT_NORMALS_ON + effectProperties: + - parentEffect: + rid: 6567500035957719299 + propertyIndex: 47 + propertyName: _FlatNormalsBlend + displayName: Blending + keywords: + - _FLAT_NORMALS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 6 + effectConfigType: 0 + extraPasses: + - effectName: CUSTOM_SHADOW_COLOR + displayName: Custom Shadow Color + group: Lighting + keywordPropertyIndex: 48 + keywordPropertyName: _CustomShadowColorOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/shadow-color + customMessages: + - message: "*You need to use ShadowsConfigurator.cs component\n in order + to use this effect." + keywords: [] + keywords: + - keyword: _CUSTOM_SHADOW_COLOR_ON + displayName: _CUSTOM_SHADOW_COLOR_ON + keywordsDisplayNames: + - _CUSTOM_SHADOW_COLOR_ON + effectProperties: [] + disabledKeyword: + displayIndex: 7 + effectConfigType: 0 + extraPasses: + - effectName: AFFECTED_BY_LIGHTMAPS + displayName: Affected by lightmaps + group: Lighting + keywordPropertyIndex: 49 + keywordPropertyName: _AffectedByLightmaps + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _AFFECTED_BY_LIGHTMAPS_ON + displayName: _AFFECTED_BY_LIGHTMAPS_ON + keywordsDisplayNames: + - _AFFECTED_BY_LIGHTMAPS_ON + effectProperties: + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 50 + propertyName: _LightmapColorCorrection + displayName: Lightmap Color Correction? + keywords: + - _AFFECTED_BY_LIGHTMAPS_ON + incompatibleKeywords: [] + propertyKeywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + fullKeywordNames: + - _LIGHTMAP_COLOR_CORRECTION_ON + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 51 + propertyName: _HueShiftLM + displayName: Hue Shift + keywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 52 + propertyName: _HueSaturationLM + displayName: Hue Saturation + keywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 53 + propertyName: _HueBrightnessLM + displayName: Hue Brightness + keywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 54 + propertyName: _ContrastLM + displayName: Contrast + keywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 55 + propertyName: _BrightnessLM + displayName: Brightness + keywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 8 + effectConfigType: 0 + extraPasses: + - effectName: CUSTOM_AMBIENT_LIGHT + displayName: Custom Ambient Light + group: Lighting + keywordPropertyIndex: 56 + keywordPropertyName: _CustomAmbientLightOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _CUSTOM_AMBIENT_LIGHT_ON + displayName: _CUSTOM_AMBIENT_LIGHT_ON + keywordsDisplayNames: + - _CUSTOM_AMBIENT_LIGHT_ON + effectProperties: + - parentEffect: + rid: 6567500035957719301 + propertyIndex: 57 + propertyName: _CustomAmbientColor + displayName: Custom Ambient Color + keywords: + - _CUSTOM_AMBIENT_LIGHT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 9 + effectConfigType: 0 + extraPasses: + - effectName: CAST_SHADOWS_ON + displayName: Cast Shadows + group: Lighting + keywordPropertyIndex: 58 + keywordPropertyName: _CastShadowsOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _CAST_SHADOWS_ON + displayName: _CAST_SHADOWS_ON + keywordsDisplayNames: + - _CAST_SHADOWS_ON + effectProperties: [] + disabledKeyword: + displayIndex: 10 + effectConfigType: 0 + extraPasses: 02000000 + - effectName: RECEIVE_SHADOWS + displayName: Receive Shadows + group: Lighting + keywordPropertyIndex: 59 + keywordPropertyName: _ReceiveShadows + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/receive-shadows-and-stylized-shadows + customMessages: + - message: "*Additional lights will not be \naffected by this effect" + keywords: + - _RECEIVEDSHADOWSTYPE_STYLIZED + keywords: + - keyword: _RECEIVE_SHADOWS_ON + displayName: _RECEIVE_SHADOWS_ON + keywordsDisplayNames: + - _RECEIVE_SHADOWS_ON + effectProperties: + - parentEffect: + rid: 6567500035957719302 + propertyIndex: 60 + propertyName: _ReceivedShadowsType + displayName: Shadow Type + keywords: + - _RECEIVE_SHADOWS_ON + incompatibleKeywords: [] + propertyKeywords: + - Classic + - Stylized + fullKeywordNames: + - _RECEIVEDSHADOWSTYPE_CLASSIC + - _RECEIVEDSHADOWSTYPE_STYLIZED + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719302 + propertyIndex: 61 + propertyName: _ShadowCutoff + displayName: Cutoff + keywords: + - _RECEIVEDSHADOWSTYPE_STYLIZED + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 11 + effectConfigType: 0 + extraPasses: 02000000 + - effectGroupConfig: {fileID: 11400000, guid: fcdc7c904b0215f4aabfa8ced0068841, type: 2} + effects: + - effectName: COLOR_RAMP + displayName: Color Ramp + group: ColorEffects + keywordPropertyIndex: 14 + keywordPropertyName: _ColorRampOn + effectDrawerID: COLOR_RAMP_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _COLOR_RAMP_ON + displayName: _COLOR_RAMP_ON + keywordsDisplayNames: + - _COLOR_RAMP_ON + effectProperties: + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 15 + propertyName: _ColorRampLightingStage + displayName: Stage + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: + - + propertyKeywords: + - BeforeLighting + - AfterLighting + fullKeywordNames: + - _COLORRAMPLIGHTINGSTAGE_BEFORELIGHTING + - _COLORRAMPLIGHTINGSTAGE_AFTERLIGHTING + keywordsOp: 0 + allowReset: 0 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 16 + propertyName: _ColorRampTex + displayName: Color Ramp Tex + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 17 + propertyName: _ColorRampLuminosity + displayName: Color Ramp Luminosity + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 18 + propertyName: _ColorRampBlend + displayName: Color Ramp Blend + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 19 + propertyName: _ColorRampTiling + displayName: Tiling + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 20 + propertyName: _ColorRampScrollSpeed + displayName: Scroll Speed + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 12 + effectConfigType: 0 + extraPasses: + - effectName: AOMAP + displayName: AO Map + group: ColorEffects + keywordPropertyIndex: 78 + keywordPropertyName: _AOMapEnabled + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _AOMAP_ON + displayName: _AOMAP_ON + keywordsDisplayNames: + - _AOMAP_ON + effectProperties: + - parentEffect: + rid: 6567500035957719304 + propertyIndex: 79 + propertyName: _AOMap + displayName: AO Map + keywords: + - _AOMAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719304 + propertyIndex: 80 + propertyName: _AOMapStrength + displayName: AO Strength + keywords: + - _AOMAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719304 + propertyIndex: 81 + propertyName: _AOContrast + displayName: AO Contrast + keywords: + - _AOMAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719304 + propertyIndex: 82 + propertyName: _AOColor + displayName: AO Color + keywords: + - _AOMAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 13 + effectConfigType: 0 + extraPasses: + - effectName: HIGHLIGHTS + displayName: Highlights + group: ColorEffects + keywordPropertyIndex: 83 + keywordPropertyName: _Highlights + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HIGHLIGHTS_ON + displayName: _HIGHLIGHTS_ON + keywordsDisplayNames: + - _HIGHLIGHTS_ON + effectProperties: + - parentEffect: + rid: 6567500035957719305 + propertyIndex: 84 + propertyName: _HighlightsColor + displayName: Highlights Color + keywords: + - _HIGHLIGHTS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719305 + propertyIndex: 85 + propertyName: _HighlightsStrength + displayName: Highlights Strength + keywords: + - _HIGHLIGHTS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719305 + propertyIndex: 86 + propertyName: _HighlightCutoff + displayName: Highlight Cutoff + keywords: + - _HIGHLIGHTS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719305 + propertyIndex: 87 + propertyName: _HighlightSmoothness + displayName: Highlight Smoothness + keywords: + - _HIGHLIGHTS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719305 + propertyIndex: 88 + propertyName: _HighlightOffset + displayName: Highlight Offset + keywords: + - _HIGHLIGHTS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 14 + effectConfigType: 0 + extraPasses: + - effectName: RIM_LIGHTING + displayName: Rim or Fresnel + group: ColorEffects + keywordPropertyIndex: 89 + keywordPropertyName: _RimLighting + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _RIM_LIGHTING_ON + displayName: _RIM_LIGHTING_ON + keywordsDisplayNames: + - _RIM_LIGHTING_ON + effectProperties: + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 90 + propertyName: _RimLightingStage + displayName: Stage + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: + - + propertyKeywords: + - BeforeLighting + - BeforeLightingLast + - AfterLighting + fullKeywordNames: + - _RIMLIGHTINGSTAGE_BEFORELIGHTING + - _RIMLIGHTINGSTAGE_BEFORELIGHTINGLAST + - _RIMLIGHTINGSTAGE_AFTERLIGHTING + keywordsOp: 0 + allowReset: 0 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 91 + propertyName: _RimColor + displayName: Rim Color + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 92 + propertyName: _RimAttenuation + displayName: Rim Attenuation + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 93 + propertyName: _MinRim + displayName: Min Rim + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 94 + propertyName: _MaxRim + displayName: Max Rim + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 95 + propertyName: _RimOffset + displayName: Rim Offset + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 15 + effectConfigType: 0 + extraPasses: + - effectName: GREYSCALE + displayName: Greyscale + group: ColorEffects + keywordPropertyIndex: 96 + keywordPropertyName: _Greyscale + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _GREYSCALE_ON + displayName: _GREYSCALE_ON + keywordsDisplayNames: + - _GREYSCALE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719307 + propertyIndex: 97 + propertyName: _GreyScaleStage + displayName: Stage + keywords: + - _GREYSCALE_ON + incompatibleKeywords: [] + propertyKeywords: + - BeforeLighting + - AfterLighting + fullKeywordNames: + - _GREYSCALESTAGE_BEFORELIGHTING + - _GREYSCALESTAGE_AFTERLIGHTING + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719307 + propertyIndex: 98 + propertyName: _GreyscaleLuminosity + displayName: Luminosity + keywords: + - _GREYSCALE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719307 + propertyIndex: 99 + propertyName: _GreyscaleTintColor + displayName: Greyscale Tint + keywords: + - _GREYSCALE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719307 + propertyIndex: 100 + propertyName: _GreyscaleBlending + displayName: Blending + keywords: + - _GREYSCALE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 16 + effectConfigType: 0 + extraPasses: + - effectName: POSTERIZE + displayName: Posterize + group: ColorEffects + keywordPropertyIndex: 101 + keywordPropertyName: _Posterize + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _POSTERIZE_ON + displayName: _POSTERIZE_ON + keywordsDisplayNames: + - _POSTERIZE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719308 + propertyIndex: 102 + propertyName: _PosterizeNumColors + displayName: Number of Colors + keywords: + - _POSTERIZE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719308 + propertyIndex: 103 + propertyName: _PosterizeGamma + displayName: Posterize Gamma + keywords: + - _POSTERIZE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 17 + effectConfigType: 0 + extraPasses: + - effectName: HUE_SHIFT + displayName: Hue Shift + group: ColorEffects + keywordPropertyIndex: 141 + keywordPropertyName: _HueShiftEnabled + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HUE_SHIFT_ON + displayName: _HUE_SHIFT_ON + keywordsDisplayNames: + - _HUE_SHIFT_ON + effectProperties: + - parentEffect: + rid: 6567500035957719309 + propertyIndex: 142 + propertyName: _HueShift + displayName: Hue Shift + keywords: + - _HUE_SHIFT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719309 + propertyIndex: 143 + propertyName: _HueSaturation + displayName: Saturation + keywords: + - _HUE_SHIFT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719309 + propertyIndex: 144 + propertyName: _HueBrightness + displayName: Brightness + keywords: + - _HUE_SHIFT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 18 + effectConfigType: 0 + extraPasses: + - effectName: EMISSION + displayName: Emission + group: ColorEffects + keywordPropertyIndex: 145 + keywordPropertyName: _EmissionEnabled + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _EMISSION_ON + displayName: _EMISSION_ON + keywordsDisplayNames: + - _EMISSION_ON + effectProperties: + - parentEffect: + rid: 6567500035957719310 + propertyIndex: 146 + propertyName: _EmissionSelfGlow + displayName: Emission Self Glow + keywords: + - _EMISSION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719310 + propertyIndex: 147 + propertyName: _EmissionColor + displayName: Emission Color + keywords: + - _EMISSION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719310 + propertyIndex: 148 + propertyName: _EmissionMap + displayName: Emission Map + keywords: + - _EMISSION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + disabledKeyword: + displayIndex: 19 + effectConfigType: 0 + extraPasses: + - effectName: HOLOGRAM + displayName: Hologram + group: ColorEffects + keywordPropertyIndex: 149 + keywordPropertyName: _Hologram + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HOLOGRAM_ON + displayName: _HOLOGRAM_ON + keywordsDisplayNames: + - _HOLOGRAM_ON + effectProperties: + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 150 + propertyName: _HologramColor + displayName: Hologram Color + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 151 + propertyName: _HologramLineDirection + displayName: Line Direction + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 152 + propertyName: _HologramBaseAlpha + displayName: Hologram Base Alpha + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 153 + propertyName: _HologramScrollSpeed + displayName: Hologram Scroll Speed + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 154 + propertyName: _HologramFrequency + displayName: Hologram Frequency + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 155 + propertyName: _HologramAlpha + displayName: Hologram Alpha + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 156 + propertyName: _HologramAccentSpeed + displayName: Hologram Accent Speed + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 157 + propertyName: _HologramAccentFrequency + displayName: Hologram Accent Frequency + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 158 + propertyName: _HologramAccentAlpha + displayName: Hologram Accent Alpha + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 159 + propertyName: _HologramLineCenter + displayName: Hologram Line Center + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 160 + propertyName: _HologramLineSpacing + displayName: Hologram Line Spacing + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 161 + propertyName: _HologramLineSmoothness + displayName: Hologram Line Smoothness + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 20 + effectConfigType: 0 + extraPasses: + - effectName: MATCAP + displayName: Matcap + group: ColorEffects + keywordPropertyIndex: 162 + keywordPropertyName: _Matcap + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _MATCAP_ON + displayName: _MATCAP_ON + keywordsDisplayNames: + - _MATCAP_ON + effectProperties: + - parentEffect: + rid: 6567500035957719312 + propertyIndex: 163 + propertyName: _MatcapBlendMode + displayName: Blend Mode + keywords: + - _MATCAP_ON + incompatibleKeywords: [] + propertyKeywords: + - Multiply + - Replace + fullKeywordNames: + - _MATCAPBLENDMODE_MULTIPLY + - _MATCAPBLENDMODE_REPLACE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719312 + propertyIndex: 164 + propertyName: _MatcapTex + displayName: Matcap Tex + keywords: + - _MATCAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719312 + propertyIndex: 165 + propertyName: _MatcapIntensity + displayName: Matcap Intensity + keywords: + - _MATCAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719312 + propertyIndex: 166 + propertyName: _MatcapBlend + displayName: Matcap Blend + keywords: + - _MATCAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 21 + effectConfigType: 0 + extraPasses: + - effectName: HIT + displayName: Hit + group: ColorEffects + keywordPropertyIndex: 167 + keywordPropertyName: _Hit + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HIT_ON + displayName: _HIT_ON + keywordsDisplayNames: + - _HIT_ON + effectProperties: + - parentEffect: + rid: 6567500035957719313 + propertyIndex: 168 + propertyName: _HitColor + displayName: Hit Color + keywords: + - _HIT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719313 + propertyIndex: 169 + propertyName: _HitGlow + displayName: Hit Glow + keywords: + - _HIT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719313 + propertyIndex: 170 + propertyName: _HitBlend + displayName: Hit Blend + keywords: + - _HIT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 22 + effectConfigType: 0 + extraPasses: + - effectName: CONTRAST_BRIGHTNESS + displayName: Contrast and Brightness + group: ColorEffects + keywordPropertyIndex: 171 + keywordPropertyName: _ContrastBrightnessOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _CONTRAST_BRIGHTNESS_ON + displayName: _CONTRAST_BRIGHTNESS_ON + keywordsDisplayNames: + - _CONTRAST_BRIGHTNESS_ON + effectProperties: + - parentEffect: + rid: 6567500035957719314 + propertyIndex: 172 + propertyName: _Contrast + displayName: Contrast + keywords: + - _CONTRAST_BRIGHTNESS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719314 + propertyIndex: 173 + propertyName: _Brightness + displayName: Brightness + keywords: + - _CONTRAST_BRIGHTNESS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 23 + effectConfigType: 0 + extraPasses: + - effectName: HEIGHT_GRADIENT + displayName: Height Gradient + group: ColorEffects + keywordPropertyIndex: 174 + keywordPropertyName: _HeightGradientOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HEIGHT_GRADIENT_ON + displayName: _HEIGHT_GRADIENT_ON + keywordsDisplayNames: + - _HEIGHT_GRADIENT_ON + effectProperties: + - parentEffect: + rid: 6567500035957719315 + propertyIndex: 175 + propertyName: _HeightGradientPositionSpace + displayName: Position Space + keywords: + - _HEIGHT_GRADIENT_ON + incompatibleKeywords: [] + propertyKeywords: + - Local + - World + fullKeywordNames: + - _HEIGHTGRADIENTPOSITIONSPACE_LOCAL + - _HEIGHTGRADIENTPOSITIONSPACE_WORLD + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719315 + propertyIndex: 176 + propertyName: _MinGradientHeight + displayName: Min Height + keywords: + - _HEIGHT_GRADIENT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719315 + propertyIndex: 177 + propertyName: _MaxGradientHeight + displayName: Max Height + keywords: + - _HEIGHT_GRADIENT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719315 + propertyIndex: 178 + propertyName: _GradientHeightColor01 + displayName: Gradient Color 01 + keywords: + - _HEIGHT_GRADIENT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719315 + propertyIndex: 179 + propertyName: _GradientHeightColor02 + displayName: Gradient Color 02 + keywords: + - _HEIGHT_GRADIENT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 24 + effectConfigType: 0 + extraPasses: + - effectName: INTERSECTION_GLOW + displayName: Intersection Glow + group: ColorEffects + keywordPropertyIndex: 180 + keywordPropertyName: _IntersectionGlowOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: + - message: '*You need to set the material to Transparent mode in order to + use this effect correctly' + keywords: [] + keywords: + - keyword: _INTERSECTION_GLOW_ON + displayName: _INTERSECTION_GLOW_ON + keywordsDisplayNames: + - _INTERSECTION_GLOW_ON + effectProperties: + - parentEffect: + rid: 6567500035957719316 + propertyIndex: 181 + propertyName: _DepthGlowDist + displayName: Depth Distance + keywords: + - _INTERSECTION_GLOW_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719316 + propertyIndex: 182 + propertyName: _DepthGlowPower + displayName: Depth Power + keywords: + - _INTERSECTION_GLOW_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719316 + propertyIndex: 183 + propertyName: _DepthGlowColor + displayName: Depth Glow Color + keywords: + - _INTERSECTION_GLOW_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719316 + propertyIndex: 184 + propertyName: _DepthGlowColorIntensity + displayName: Color Intensity + keywords: + - _INTERSECTION_GLOW_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719316 + propertyIndex: 185 + propertyName: _DepthGlowGlobalIntensity + displayName: Global Intensity + keywords: + - _INTERSECTION_GLOW_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 25 + effectConfigType: 0 + extraPasses: + - effectName: ALBEDO_VERTEX_COLOR + displayName: Albedo From Vertex Color + group: ColorEffects + keywordPropertyIndex: 186 + keywordPropertyName: _AlbedoVertexColorOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _ALBEDO_VERTEX_COLOR_ON + displayName: _ALBEDO_VERTEX_COLOR_ON + keywordsDisplayNames: + - _ALBEDO_VERTEX_COLOR_ON + effectProperties: + - parentEffect: + rid: 6567500035957719317 + propertyIndex: 187 + propertyName: _AlbedoVertexColorMode + displayName: Mode + keywords: + - _ALBEDO_VERTEX_COLOR_ON + incompatibleKeywords: [] + propertyKeywords: + - Multiply + - Replace + fullKeywordNames: + - _ALBEDOVERTEXCOLORMODE_MULTIPLY + - _ALBEDOVERTEXCOLORMODE_REPLACE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719317 + propertyIndex: 188 + propertyName: _VertexColorBlending + displayName: Blending + keywords: + - _ALBEDO_VERTEX_COLOR_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 26 + effectConfigType: 0 + extraPasses: + - effectName: TRIPLANAR_MAPPING + displayName: Triplanar Mapping + group: ColorEffects + keywordPropertyIndex: 189 + keywordPropertyName: _TriplanarMappingOn + effectDrawerID: TRIPLANAR_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: SCREEN_SPACE_UV + docURL: + customMessages: [] + keywords: + - keyword: _TRIPLANAR_MAPPING_ON + displayName: _TRIPLANAR_MAPPING_ON + keywordsDisplayNames: + - _TRIPLANAR_MAPPING_ON + effectProperties: + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 190 + propertyName: _TriplanarNormalSpace + displayName: UV Space + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: + - Local + - World + fullKeywordNames: + - _TRIPLANARNORMALSPACE_LOCAL + - _TRIPLANARNORMALSPACE_WORLD + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 191 + propertyName: _TriplanarTopTex + displayName: Top Texture + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 192 + propertyName: _TriplanarTopNormalMap + displayName: Top Normal Map + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 193 + propertyName: _TopNormalStrength + displayName: Top Normal Map Strength + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 194 + propertyName: _FaceDownCutoff + displayName: Face Down Cutoff + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 195 + propertyName: _TriplanarSharpness + displayName: Sharpness + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 196 + propertyName: _TriplanarNoiseTransitionOn + displayName: Noise Transition + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: + - _TRIPLANAR_NOISE_TRANSITION_ON + fullKeywordNames: + - _TRIPLANAR_NOISE_TRANSITION_ON + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 197 + propertyName: _TriplanarNoiseTex + displayName: Noise Tex + keywords: + - _TRIPLANAR_NOISE_TRANSITION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 198 + propertyName: _TriplanarTransitionPower + displayName: Transition Power + keywords: + - _TRIPLANAR_NOISE_TRANSITION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 27 + effectConfigType: 0 + extraPasses: + - effectName: TEXTURE_BLENDING + displayName: Texture Blending + group: ColorEffects + keywordPropertyIndex: 199 + keywordPropertyName: _TextureBlending + effectDrawerID: TEXTURE_BLENDING_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _TEXTURE_BLENDING_ON + displayName: _TEXTURE_BLENDING_ON + keywordsDisplayNames: + - _TEXTURE_BLENDING_ON + effectProperties: + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 200 + propertyName: _TextureBlendingSource + displayName: Source + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: + - VertexColor + - Texture + fullKeywordNames: + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + - _TEXTUREBLENDINGSOURCE_TEXTURE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 201 + propertyName: _TexBlendingMask + displayName: Texture Blending Mask + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 202 + propertyName: _BlendingMaskCutoffG + displayName: Cutoff (G) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 203 + propertyName: _BlendingMaskSmoothnessG + displayName: Smoothness (G) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 204 + propertyName: _BlendingMaskCutoffB + displayName: Cutoff (B) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 205 + propertyName: _BlendingMaskSmoothnessB + displayName: Smoothness (B) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 206 + propertyName: _BlendingMaskCutoffWhite + displayName: Cutoff (White) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 207 + propertyName: _BlendingMaskSmoothnessWhite + displayName: Smoothness (White) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 208 + propertyName: _TextureBlendingMode + displayName: Blending Mode + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: + - RGB + - BlackAndWhite + fullKeywordNames: + - _TEXTUREBLENDINGMODE_RGB + - _TEXTUREBLENDINGMODE_BLACKANDWHITE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 209 + propertyName: _BlendingTextureG + displayName: Blending Texture (G) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 210 + propertyName: _BlendingTextureB + displayName: Blending Texture (B) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 211 + propertyName: _BlendingTextureWhite + displayName: Blending Texture (White) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 212 + propertyName: _BlendingNormalMapG + displayName: Blending Normal Map (G) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 213 + propertyName: _BlendingNormalMapB + displayName: Blending Normal Map (B) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 214 + propertyName: _BlendingNormalMapWhite + displayName: Blending Normal Map (White) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 28 + effectConfigType: 0 + extraPasses: + - effectName: DEPTH_COLORING + displayName: Depth Coloring + group: ColorEffects + keywordPropertyIndex: 215 + keywordPropertyName: _DepthColoringOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/depth-coloring-stylized-fog + customMessages: + - message: "*You need to add DepthColoringCamera.cs component \nto the main + camera in order to use this effect." + keywords: [] + keywords: + - keyword: _DEPTH_COLORING_ON + displayName: _DEPTH_COLORING_ON + keywordsDisplayNames: + - _DEPTH_COLORING_ON + effectProperties: [] + disabledKeyword: + displayIndex: 29 + effectConfigType: 0 + extraPasses: + - effectName: SUBSURFACE_SCATTERING + displayName: Fake Subsurface Scattering + group: ColorEffects + keywordPropertyIndex: 216 + keywordPropertyName: _SubsurfaceScattering + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _SUBSURFACE_SCATTERING_ON + displayName: _SUBSURFACE_SCATTERING_ON + keywordsDisplayNames: + - _SUBSURFACE_SCATTERING_ON + effectProperties: + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 217 + propertyName: _NormalInfluence + displayName: Normal Influence + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 218 + propertyName: _SSSPower + displayName: SSS Power + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 219 + propertyName: _SSSFrontPower + displayName: SSS Front Power + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 220 + propertyName: _SSSFrontAtten + displayName: SSS Front Atten + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 221 + propertyName: _SSSAtten + displayName: SSS General Atten + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 222 + propertyName: _SSSColor + displayName: SSS Color + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 223 + propertyName: _SSSMap + displayName: SSS Map + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + disabledKeyword: + displayIndex: 30 + effectConfigType: 0 + extraPasses: + - effectGroupConfig: {fileID: 11400000, guid: d45649322d809684a8f280736df5ebc7, type: 2} + effects: + - effectName: ALPHA_CUTOFF + displayName: Alpha Cutoff + group: AlphaEffects + keywordPropertyIndex: 224 + keywordPropertyName: _AlphaCutoffOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _ALPHA_CUTOFF_ON + displayName: _ALPHA_CUTOFF_ON + keywordsDisplayNames: + - _ALPHA_CUTOFF_ON + effectProperties: + - parentEffect: + rid: 6567500035957719321 + propertyIndex: 225 + propertyName: _AlphaCutoffValue + displayName: Cutoff Value + keywords: + - _ALPHA_CUTOFF_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 31 + effectConfigType: 0 + extraPasses: + - effectName: FADE + displayName: Fade + group: AlphaEffects + keywordPropertyIndex: 226 + keywordPropertyName: _FadeOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _FADE_ON + displayName: _FADE_ON + keywordsDisplayNames: + - _FADE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 227 + propertyName: _FadeTex + displayName: Fade Tex + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 228 + propertyName: _FadeUVSet + displayName: UV Set + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: + - UV1 + - UV2 + - WORLD_SPACE + fullKeywordNames: + - _FADEUVSET_UV1 + - _FADEUVSET_UV2 + - _FADEUVSET_WORLD_SPACE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 229 + propertyName: _FadeAmount + displayName: Fade Amount + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 230 + propertyName: _FadePower + displayName: Fade Power + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 231 + propertyName: _FadeTransition + displayName: Fade Transition + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 232 + propertyName: _FadeBurnOn + displayName: Use Fade Burn Color? + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: + - _FADE_BURN_ON + fullKeywordNames: + - _FADE_BURN_ON + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 233 + propertyName: _FadeBurnColor + displayName: Fade Burn Color + keywords: + - _FADE_BURN_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 234 + propertyName: _FadeBurnWidth + displayName: Fade Burn Width + keywords: + - _FADE_BURN_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 32 + effectConfigType: 0 + extraPasses: + - effectName: INTERSECTION_FADE + displayName: Intersection Fade + group: AlphaEffects + keywordPropertyIndex: 235 + keywordPropertyName: _IntersectionFadeOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: + - message: '*You need to set the material to Transparent mode in order to + use this effect correctly' + keywords: [] + keywords: + - keyword: _INTERSECTION_FADE_ON + displayName: _INTERSECTION_FADE_ON + keywordsDisplayNames: + - _INTERSECTION_FADE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719323 + propertyIndex: 236 + propertyName: _IntersectionFadeFactor + displayName: Intersection Fade Factor + keywords: + - _INTERSECTION_FADE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 33 + effectConfigType: 0 + extraPasses: + - effectName: ALPHA_ROUND + displayName: Alpha Round + group: AlphaEffects + keywordPropertyIndex: 237 + keywordPropertyName: _AlphaRoundOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _ALPHA_ROUND_ON + displayName: _ALPHA_ROUND_ON + keywordsDisplayNames: + - _ALPHA_ROUND_ON + effectProperties: [] + disabledKeyword: + displayIndex: 34 + effectConfigType: 0 + extraPasses: + - effectName: FADE_BY_CAM_DISTANCE + displayName: Fade By Cam Distance + group: AlphaEffects + keywordPropertyIndex: 238 + keywordPropertyName: _FadeByCamDistanceOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _FADE_BY_CAM_DISTANCE_ON + displayName: _FADE_BY_CAM_DISTANCE_ON + keywordsDisplayNames: + - _FADE_BY_CAM_DISTANCE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719324 + propertyIndex: 239 + propertyName: _NearFade + displayName: Near Fade + keywords: + - _FADE_BY_CAM_DISTANCE_ON + incompatibleKeywords: [] + propertyKeywords: + - _FADE_BY_CAM_DISTANCE_NEAR_FADE + fullKeywordNames: + - _FADE_BY_CAM_DISTANCE_NEAR_FADE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719324 + propertyIndex: 240 + propertyName: _MinDistanceToFade + displayName: Min Distance + keywords: + - _FADE_BY_CAM_DISTANCE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719324 + propertyIndex: 241 + propertyName: _MaxDistanceToFade + displayName: Max Distance + keywords: + - _FADE_BY_CAM_DISTANCE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 35 + effectConfigType: 0 + extraPasses: + - effectName: DITHER + displayName: Dither + group: AlphaEffects + keywordPropertyIndex: 242 + keywordPropertyName: _DitherOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _DITHER_ON + displayName: _DITHER_ON + keywordsDisplayNames: + - _DITHER_ON + effectProperties: + - parentEffect: + rid: 6567500035957719325 + propertyIndex: 243 + propertyName: _DitherScale + displayName: Scale + keywords: + - _DITHER_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 36 + effectConfigType: 0 + extraPasses: + - effectGroupConfig: {fileID: 11400000, guid: 987f969d8d3fec24bbb35df7779ba52b, type: 2} + effects: + - effectName: VERTEX_SHAKE + displayName: Vertex Shake + group: MeshEffects + keywordPropertyIndex: 112 + keywordPropertyName: _VertexShakeOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _VERTEX_SHAKE_ON + displayName: _VERTEX_SHAKE_ON + keywordsDisplayNames: + - _VERTEX_SHAKE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719326 + propertyIndex: 113 + propertyName: _ShakeSpeed + displayName: Speed + keywords: + - _VERTEX_SHAKE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719326 + propertyIndex: 114 + propertyName: _ShakeSpeedMult + displayName: Shake Mult + keywords: + - _VERTEX_SHAKE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719326 + propertyIndex: 115 + propertyName: _ShakeMaxDisplacement + displayName: Shake Max Displacement + keywords: + - _VERTEX_SHAKE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719326 + propertyIndex: 116 + propertyName: _ShakeBlend + displayName: Shake Blend + keywords: + - _VERTEX_SHAKE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 37 + effectConfigType: 0 + extraPasses: + - effectName: VERTEX_INFLATE + displayName: Vertex Inflate + group: MeshEffects + keywordPropertyIndex: 117 + keywordPropertyName: _VertexInflate + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _VERTEX_INFLATE_ON + displayName: _VERTEX_INFLATE_ON + keywordsDisplayNames: + - _VERTEX_INFLATE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719327 + propertyIndex: 118 + propertyName: _MinInflate + displayName: Min Inflate + keywords: + - _VERTEX_INFLATE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719327 + propertyIndex: 119 + propertyName: _MaxInflate + displayName: Max Inflate + keywords: + - _VERTEX_INFLATE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719327 + propertyIndex: 120 + propertyName: _InflateBlend + displayName: Inflate blend + keywords: + - _VERTEX_INFLATE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 38 + effectConfigType: 0 + extraPasses: + - effectName: VERTEX_DISTORTION + displayName: Vertex Distortion + group: MeshEffects + keywordPropertyIndex: 121 + keywordPropertyName: _VertexDistortionOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _VERTEX_DISTORTION_ON + displayName: _VERTEX_DISTORTION_ON + keywordsDisplayNames: + - _VERTEX_DISTORTION_ON + effectProperties: + - parentEffect: + rid: 6567500035957719328 + propertyIndex: 122 + propertyName: _VertexDistortionNoiseTex + displayName: Noise Tex + keywords: + - _VERTEX_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719328 + propertyIndex: 123 + propertyName: _VertexDistortionAmount + displayName: Distortion Amount + keywords: + - _VERTEX_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719328 + propertyIndex: 124 + propertyName: _VertexDistortionNoiseSpeedX + displayName: Scroll Speed X + keywords: + - _VERTEX_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719328 + propertyIndex: 125 + propertyName: _VertexDistortionNoiseSpeedY + displayName: Scroll Speed Y + keywords: + - _VERTEX_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 39 + effectConfigType: 0 + extraPasses: + - effectName: VOXELIZE + displayName: Voxelize + group: MeshEffects + keywordPropertyIndex: 126 + keywordPropertyName: _Voxelize + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _VOXELIZE_ON + displayName: _VOXELIZE_ON + keywordsDisplayNames: + - _VOXELIZE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719329 + propertyIndex: 127 + propertyName: _VoxelSize + displayName: Voxel Size + keywords: + - _VOXELIZE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719329 + propertyIndex: 128 + propertyName: _VoxelBlend + displayName: Blend Amount + keywords: + - _VOXELIZE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 40 + effectConfigType: 0 + extraPasses: + - effectName: GLITCH + displayName: Glitch + group: MeshEffects + keywordPropertyIndex: 129 + keywordPropertyName: _Glitch + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _GLITCH_ON + displayName: _GLITCH_ON + keywordsDisplayNames: + - _GLITCH_ON + effectProperties: + - parentEffect: + rid: 6567500035957719330 + propertyIndex: 130 + propertyName: _GlitchTiling + displayName: Glitch Tiling + keywords: + - _GLITCH_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719330 + propertyIndex: 131 + propertyName: _GlitchAmount + displayName: Glitch Amount + keywords: + - _GLITCH_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719330 + propertyIndex: 132 + propertyName: _GlitchOffset + displayName: Glitch Offset + keywords: + - _GLITCH_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719330 + propertyIndex: 133 + propertyName: _GlitchSpeed + displayName: Glitch Speed + keywords: + - _GLITCH_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719330 + propertyIndex: 134 + propertyName: _GlitchWorldSpace + displayName: Use World Space + keywords: + - _GLITCH_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 41 + effectConfigType: 0 + extraPasses: + - effectName: RECALCULATE_NORMALS + displayName: Recalculate Normals + group: MeshEffects + keywordPropertyIndex: 135 + keywordPropertyName: _RecalculateNormals + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: + - message: '*Dynamically reconstructs surface normals from vertex positions, + ignoring mesh baked normals' + keywords: + - _SHADINGMODEL_PBR + keywords: + - keyword: _RECALCULATE_NORMALS_ON + displayName: _RECALCULATE_NORMALS_ON + keywordsDisplayNames: + - _RECALCULATE_NORMALS_ON + effectProperties: [] + disabledKeyword: + displayIndex: 42 + effectConfigType: 0 + extraPasses: + - effectName: WIND + displayName: Wind + group: MeshEffects + keywordPropertyIndex: 136 + keywordPropertyName: _WindOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/wind-effect-and-wind-controller + customMessages: + - message: "*You need to use WindController.cs component\n in order to use + this effect." + keywords: [] + keywords: + - keyword: _WIND_ON + displayName: _WIND_ON + keywordsDisplayNames: + - _WIND_ON + effectProperties: + - parentEffect: + rid: 6567500035957719331 + propertyIndex: 137 + propertyName: _WindAttenuation + displayName: Attenuation + keywords: + - _WIND_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719331 + propertyIndex: 138 + propertyName: _UseVerticalMask + displayName: Use Vertical Mask? + keywords: + - _WIND_ON + incompatibleKeywords: [] + propertyKeywords: + - _USE_WIND_VERTICAL_MASK + fullKeywordNames: + - _USE_WIND_VERTICAL_MASK + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719331 + propertyIndex: 139 + propertyName: _WindVerticalMaskMinY + displayName: Min Y + keywords: + - _USE_WIND_VERTICAL_MASK + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719331 + propertyIndex: 140 + propertyName: _WindVerticalMaskMaxY + displayName: Max Y + keywords: + - _USE_WIND_VERTICAL_MASK + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 43 + effectConfigType: 0 + extraPasses: + - effectGroupConfig: {fileID: 11400000, guid: 2f3fcb0996a83b64599ce17553aa6b13, type: 2} + effects: + - effectName: SCROLL_TEXTURE + displayName: Scroll Texture + group: UVEffects + keywordPropertyIndex: 62 + keywordPropertyName: _ScrollTextureOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _SCROLL_TEXTURE_ON + displayName: _SCROLL_TEXTURE_ON + keywordsDisplayNames: + - _SCROLL_TEXTURE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719332 + propertyIndex: 63 + propertyName: _ScrollTextureX + displayName: Scroll X + keywords: + - _SCROLL_TEXTURE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719332 + propertyIndex: 64 + propertyName: _ScrollTextureY + displayName: Scroll Y + keywords: + - _SCROLL_TEXTURE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 44 + effectConfigType: 0 + extraPasses: + - effectName: SCREEN_SPACE_UV + displayName: Screen Space UV + group: UVEffects + keywordPropertyIndex: 65 + keywordPropertyName: _ScreenSpaceUVOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: TRIPLANAR_MAPPING + docURL: + customMessages: [] + keywords: + - keyword: _SCREEN_SPACE_UV_ON + displayName: _SCREEN_SPACE_UV_ON + keywordsDisplayNames: + - _SCREEN_SPACE_UV_ON + effectProperties: + - parentEffect: + rid: 6567500035957719333 + propertyIndex: 66 + propertyName: _ScaleWithCameraDistance + displayName: Scale with camera distance + keywords: + - _SCREEN_SPACE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 45 + effectConfigType: 0 + extraPasses: + - effectName: PIXELATE + displayName: Pixelate + group: UVEffects + keywordPropertyIndex: 67 + keywordPropertyName: _Pixelate + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _PIXELATE_ON + displayName: _PIXELATE_ON + keywordsDisplayNames: + - _PIXELATE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719334 + propertyIndex: 68 + propertyName: _PixelateSize + displayName: Pixelate Size + keywords: + - _PIXELATE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 46 + effectConfigType: 0 + extraPasses: + - effectName: STOCHASTIC_SAMPLING + displayName: Stochastic Sampling + group: UVEffects + keywordPropertyIndex: 69 + keywordPropertyName: _StochasticSampling + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _STOCHASTIC_SAMPLING_ON + displayName: _STOCHASTIC_SAMPLING_ON + keywordsDisplayNames: + - _STOCHASTIC_SAMPLING_ON + effectProperties: + - parentEffect: + rid: 6567500035957719335 + propertyIndex: 70 + propertyName: _StochasticScale + displayName: Grid Scale + keywords: + - _STOCHASTIC_SAMPLING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719335 + propertyIndex: 71 + propertyName: _StochasticSkew + displayName: Grid Skew + keywords: + - _STOCHASTIC_SAMPLING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 47 + effectConfigType: 0 + extraPasses: + - effectName: WAVE_UV + displayName: Wave UV On + group: UVEffects + keywordPropertyIndex: 72 + keywordPropertyName: _WaveUVOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _WAVE_UV_ON + displayName: _WAVE_UV_ON + keywordsDisplayNames: + - _WAVE_UV_ON + effectProperties: + - parentEffect: + rid: 6567500035957719336 + propertyIndex: 73 + propertyName: _WaveAmount + displayName: Wave Amount + keywords: + - _WAVE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719336 + propertyIndex: 74 + propertyName: _WaveSpeed + displayName: Wave Speed + keywords: + - _WAVE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719336 + propertyIndex: 75 + propertyName: _WaveStrength + displayName: Wave Strength + keywords: + - _WAVE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719336 + propertyIndex: 76 + propertyName: _WaveX + displayName: Wave X Axis + keywords: + - _WAVE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719336 + propertyIndex: 77 + propertyName: _WaveY + displayName: Wave Y Axis + keywords: + - _WAVE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 48 + effectConfigType: 0 + extraPasses: + - effectName: HAND_DRAWN + displayName: Hand Drawn + group: UVEffects + keywordPropertyIndex: 104 + keywordPropertyName: _HandDrawn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HAND_DRAWN_ON + displayName: _HAND_DRAWN_ON + keywordsDisplayNames: + - _HAND_DRAWN_ON + effectProperties: + - parentEffect: + rid: 6567500035957719337 + propertyIndex: 105 + propertyName: _HandDrawnAmount + displayName: Hand Drawn Amount + keywords: + - _HAND_DRAWN_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719337 + propertyIndex: 106 + propertyName: _HandDrawnSpeed + displayName: Hand Drawn Speed + keywords: + - _HAND_DRAWN_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 49 + effectConfigType: 0 + extraPasses: + - effectName: UV_DISTORTION + displayName: Distortion + group: UVEffects + keywordPropertyIndex: 107 + keywordPropertyName: _UVDistortion + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _UV_DISTORTION_ON + displayName: _UV_DISTORTION_ON + keywordsDisplayNames: + - _UV_DISTORTION_ON + effectProperties: + - parentEffect: + rid: 6567500035957719338 + propertyIndex: 108 + propertyName: _DistortTex + displayName: Distortion Texture + keywords: + - _UV_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719338 + propertyIndex: 109 + propertyName: _DistortAmount + displayName: Distortion Amount + keywords: + - _UV_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719338 + propertyIndex: 110 + propertyName: _DistortTexXSpeed + displayName: Scroll speed X + keywords: + - _UV_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719338 + propertyIndex: 111 + propertyName: _DistortTexYSpeed + displayName: Scroll speed Y + keywords: + - _UV_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 50 + effectConfigType: 0 + extraPasses: + - effectGroupConfig: {fileID: 11400000, guid: d29aa9c55e3576d4bad55ec71545fe82, type: 2} + effects: + - effectName: OUTLINETYPE + displayName: Outline Type + group: OtherEffects + keywordPropertyIndex: 244 + keywordPropertyName: _OutlineType + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: + - message: '*If the material is transparent, you need to enable Depth Write. + Otherwise, the mesh will look completely black + +' + keywords: + - _OUTLINETYPE_SIMPLE + - _OUTLINETYPE_CONSTANT + - _OUTLINETYPE_FADEWITHDISTANCE + keywords: + - keyword: _OUTLINETYPE_NONE + displayName: None + - keyword: _OUTLINETYPE_SIMPLE + displayName: Simple + - keyword: _OUTLINETYPE_CONSTANT + displayName: Constant + - keyword: _OUTLINETYPE_FADEWITHDISTANCE + displayName: FadeWithDistance + keywordsDisplayNames: + - None + - Simple + - Constant + - FadeWithDistance + effectProperties: + - parentEffect: + rid: 6567500035957719339 + propertyIndex: 246 + propertyName: _OutlineColor + displayName: Outline Color + keywords: + - _OUTLINETYPE_SIMPLE + - _OUTLINETYPE_CONSTANT + - _OUTLINETYPE_FADEWITHDISTANCE + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719339 + propertyIndex: 247 + propertyName: _MaxCameraDistance + displayName: Max Camera Distance + keywords: + - _OUTLINETYPE_CONSTANT + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719339 + propertyIndex: 248 + propertyName: _MaxFadeDistance + displayName: Max Fade Distance + keywords: + - _OUTLINETYPE_FADEWITHDISTANCE + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719339 + propertyIndex: 249 + propertyName: _OutlineThickness + displayName: Outline Thickness + keywords: + - _OUTLINETYPE_SIMPLE + - _OUTLINETYPE_CONSTANT + - _OUTLINETYPE_FADEWITHDISTANCE + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719339 + propertyIndex: 250 + propertyName: _OutlineMode + displayName: Outline Mode + keywords: + - _OUTLINETYPE_SIMPLE + - _OUTLINETYPE_CONSTANT + - _OUTLINETYPE_FADEWITHDISTANCE + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 51 + effectConfigType: 1 + extraPasses: 01000000 + singleProperties: 0b0000000c0000000d000000 + advancedProperties: 010000000400000005000000060000000700000008000000090000000a000000 + renderPreset: 0 + blendSrcIdx: 2 + blendDstIdx: 3 + zWriteIndex: 5 + references: + version: 2 + RefIds: + - rid: 6567500035957719294 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: LIGHTMODEL + displayName: Light Model + group: Lighting + keywordPropertyIndex: 21 + keywordPropertyName: _LightModel + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/fast-lighting + customMessages: + - message: "*You need to use FastLightConfigurator.cs component\n in order + to use this effect." + keywords: + - _LIGHTMODEL_FASTLIGHTING + keywords: + - keyword: _LIGHTMODEL_NONE + displayName: None + - keyword: _LIGHTMODEL_CLASSIC + displayName: Classic + - keyword: _LIGHTMODEL_TOON + displayName: Toon + - keyword: _LIGHTMODEL_TOONRAMP + displayName: ToonRamp + - keyword: _LIGHTMODEL_HALFLAMBERT + displayName: HalfLambert + - keyword: _LIGHTMODEL_FAKEGI + displayName: FakeGI + - keyword: _LIGHTMODEL_FASTLIGHTING + displayName: FastLighting + keywordsDisplayNames: + - None + - Classic + - Toon + - ToonRamp + - HalfLambert + - FakeGI + - FastLighting + effectProperties: + - parentEffect: + rid: 6567500035957719294 + propertyIndex: 22 + propertyName: _ToonCutoff + displayName: Toon Cutoff + keywords: + - _LIGHTMODEL_TOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719294 + propertyIndex: 23 + propertyName: _ToonSmoothness + displayName: Toon Smoothness + keywords: + - _LIGHTMODEL_TOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719294 + propertyIndex: 24 + propertyName: _ToonRamp + displayName: Toon Ramp + keywords: + - _LIGHTMODEL_TOONRAMP + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719294 + propertyIndex: 25 + propertyName: _HalfLambertWrap + displayName: Half Lambert + keywords: + - _LIGHTMODEL_HALFLAMBERT + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719294 + propertyIndex: 26 + propertyName: _HardnessFakeGI + displayName: Fake GI Hardness + keywords: + - _LIGHTMODEL_FAKEGI + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 1 + effectConfigType: 1 + extraPasses: 06000000 + - rid: 6567500035957719295 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: SHADINGMODEL + displayName: Shading Model + group: Lighting + keywordPropertyIndex: 27 + keywordPropertyName: _ShadingModel + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: LIGHTMODEL + incompatibleWithEffectID: + docURL: + customMessages: + - message: '*Usually looks best paired with a Specular Model' + keywords: + - _SHADINGMODEL_PBR + keywords: + - keyword: _SHADINGMODEL_BASIC + displayName: Basic + - keyword: _SHADINGMODEL_PBR + displayName: PBR + keywordsDisplayNames: + - Basic + - PBR + effectProperties: + - parentEffect: + rid: 6567500035957719295 + propertyIndex: 28 + propertyName: _Metallic + displayName: Metallic + keywords: + - _SHADINGMODEL_PBR + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719295 + propertyIndex: 29 + propertyName: _Smoothness + displayName: Smoothness + keywords: + - _SHADINGMODEL_PBR + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719295 + propertyIndex: 30 + propertyName: _MetallicMapOn + displayName: Use Metallic(R) / Smoothness(A) Map? + keywords: + - _SHADINGMODEL_PBR + incompatibleKeywords: + - + propertyKeywords: + - _METALLIC_MAP_ON + fullKeywordNames: + - _METALLIC_MAP_ON + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719295 + propertyIndex: 31 + propertyName: _MetallicMap + displayName: Metallic Map + keywords: + - _SHADINGMODEL_PBR + - _METALLIC_MAP_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 1 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + disabledKeyword: + displayIndex: 2 + effectConfigType: 1 + extraPasses: + - rid: 6567500035957719296 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: SPECULARMODEL + displayName: Specular Model + group: Lighting + keywordPropertyIndex: 32 + keywordPropertyName: _SpecularModel + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: LIGHTMODEL + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _SPECULARMODEL_NONE + displayName: None + - keyword: _SPECULARMODEL_CLASSIC + displayName: Classic + - keyword: _SPECULARMODEL_TOON + displayName: Toon + - keyword: _SPECULARMODEL_ANISOTROPIC + displayName: Anisotropic + - keyword: _SPECULARMODEL_ANISOTROPICTOON + displayName: AnisotropicToon + keywordsDisplayNames: + - None + - Classic + - Toon + - Anisotropic + - AnisotropicToon + effectProperties: + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 33 + propertyName: _SpecularAtten + displayName: Specular Attenuation + keywords: + - _SPECULARMODEL_CLASSIC + - _SPECULARMODEL_TOON + - _SPECULARMODEL_ANISOTROPIC + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 34 + propertyName: _Shininess + displayName: Shininess + keywords: + - _SPECULARMODEL_CLASSIC + - _SPECULARMODEL_TOON + incompatibleKeywords: + - _SHADINGMODEL_PBR + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 35 + propertyName: _AnisoShininess + displayName: Aniso Shininess + keywords: + - _SPECULARMODEL_ANISOTROPIC + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: + - _SHADINGMODEL_PBR + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 36 + propertyName: _SpecularToonCutoff + displayName: Specular Toon Cutoff + keywords: + - _SPECULARMODEL_TOON + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 37 + propertyName: _SpecularToonSmoothness + displayName: Specular Toon Smoothness + keywords: + - _SPECULARMODEL_TOON + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 38 + propertyName: _SpecularMap + displayName: Specular Map + keywords: + - _SPECULARMODEL_CLASSIC + - _SPECULARMODEL_TOON + - _SPECULARMODEL_ANISOTROPIC + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719296 + propertyIndex: 39 + propertyName: _Anisotropy + displayName: Anisotropy + keywords: + - _SPECULARMODEL_ANISOTROPIC + - _SPECULARMODEL_ANISOTROPICTOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 3 + effectConfigType: 1 + extraPasses: + - rid: 6567500035957719297 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: REFLECTIONS + displayName: Reflections + group: Lighting + keywordPropertyIndex: 40 + keywordPropertyName: _Reflections + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: LIGHTMODEL + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _REFLECTIONS_NONE + displayName: None + - keyword: _REFLECTIONS_CLASSIC + displayName: Classic + - keyword: _REFLECTIONS_TOON + displayName: Toon + keywordsDisplayNames: + - None + - Classic + - Toon + effectProperties: + - parentEffect: + rid: 6567500035957719297 + propertyIndex: 41 + propertyName: _ToonFactor + displayName: Toon Factor + keywords: + - _REFLECTIONS_TOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719297 + propertyIndex: 42 + propertyName: _ReflectionsAtten + displayName: Attenuation + keywords: + - _REFLECTIONS_CLASSIC + - _REFLECTIONS_TOON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 4 + effectConfigType: 1 + extraPasses: + - rid: 6567500035957719298 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: NORMAL_MAP + displayName: Normal Map + group: Lighting + keywordPropertyIndex: 43 + keywordPropertyName: _NormalMapEnabled + effectDrawerID: NORMAL_MAP_EFFECT_DRAWER + dependentOnEffect: LIGHTMODEL + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _NORMAL_MAP_ON + displayName: _NORMAL_MAP_ON + keywordsDisplayNames: + - _NORMAL_MAP_ON + effectProperties: + - parentEffect: + rid: 6567500035957719298 + propertyIndex: 44 + propertyName: _NormalMap + displayName: Normal Map + keywords: + - _NORMAL_MAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719298 + propertyIndex: 45 + propertyName: _NormalStrength + displayName: Normal Strength + keywords: + - _NORMAL_MAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 5 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719299 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: FLAT_NORMALS + displayName: Flat Normals + group: Lighting + keywordPropertyIndex: 46 + keywordPropertyName: _FlatNormalsEnabled + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: LIGHTMODEL + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _FLAT_NORMALS_ON + displayName: _FLAT_NORMALS_ON + keywordsDisplayNames: + - _FLAT_NORMALS_ON + effectProperties: + - parentEffect: + rid: 6567500035957719299 + propertyIndex: 47 + propertyName: _FlatNormalsBlend + displayName: Blending + keywords: + - _FLAT_NORMALS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 6 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719300 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: AFFECTED_BY_LIGHTMAPS + displayName: Affected by lightmaps + group: Lighting + keywordPropertyIndex: 49 + keywordPropertyName: _AffectedByLightmaps + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _AFFECTED_BY_LIGHTMAPS_ON + displayName: _AFFECTED_BY_LIGHTMAPS_ON + keywordsDisplayNames: + - _AFFECTED_BY_LIGHTMAPS_ON + effectProperties: + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 50 + propertyName: _LightmapColorCorrection + displayName: Lightmap Color Correction? + keywords: + - _AFFECTED_BY_LIGHTMAPS_ON + incompatibleKeywords: [] + propertyKeywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + fullKeywordNames: + - _LIGHTMAP_COLOR_CORRECTION_ON + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 51 + propertyName: _HueShiftLM + displayName: Hue Shift + keywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 52 + propertyName: _HueSaturationLM + displayName: Hue Saturation + keywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 53 + propertyName: _HueBrightnessLM + displayName: Hue Brightness + keywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 54 + propertyName: _ContrastLM + displayName: Contrast + keywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719300 + propertyIndex: 55 + propertyName: _BrightnessLM + displayName: Brightness + keywords: + - _LIGHTMAP_COLOR_CORRECTION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 8 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719301 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: CUSTOM_AMBIENT_LIGHT + displayName: Custom Ambient Light + group: Lighting + keywordPropertyIndex: 56 + keywordPropertyName: _CustomAmbientLightOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _CUSTOM_AMBIENT_LIGHT_ON + displayName: _CUSTOM_AMBIENT_LIGHT_ON + keywordsDisplayNames: + - _CUSTOM_AMBIENT_LIGHT_ON + effectProperties: + - parentEffect: + rid: 6567500035957719301 + propertyIndex: 57 + propertyName: _CustomAmbientColor + displayName: Custom Ambient Color + keywords: + - _CUSTOM_AMBIENT_LIGHT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 9 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719302 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: RECEIVE_SHADOWS + displayName: Receive Shadows + group: Lighting + keywordPropertyIndex: 59 + keywordPropertyName: _ReceiveShadows + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/receive-shadows-and-stylized-shadows + customMessages: + - message: "*Additional lights will not be \naffected by this effect" + keywords: + - _RECEIVEDSHADOWSTYPE_STYLIZED + keywords: + - keyword: _RECEIVE_SHADOWS_ON + displayName: _RECEIVE_SHADOWS_ON + keywordsDisplayNames: + - _RECEIVE_SHADOWS_ON + effectProperties: + - parentEffect: + rid: 6567500035957719302 + propertyIndex: 60 + propertyName: _ReceivedShadowsType + displayName: Shadow Type + keywords: + - _RECEIVE_SHADOWS_ON + incompatibleKeywords: [] + propertyKeywords: + - Classic + - Stylized + fullKeywordNames: + - _RECEIVEDSHADOWSTYPE_CLASSIC + - _RECEIVEDSHADOWSTYPE_STYLIZED + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719302 + propertyIndex: 61 + propertyName: _ShadowCutoff + displayName: Cutoff + keywords: + - _RECEIVEDSHADOWSTYPE_STYLIZED + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 11 + effectConfigType: 0 + extraPasses: 02000000 + - rid: 6567500035957719303 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: COLOR_RAMP + displayName: Color Ramp + group: ColorEffects + keywordPropertyIndex: 14 + keywordPropertyName: _ColorRampOn + effectDrawerID: COLOR_RAMP_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _COLOR_RAMP_ON + displayName: _COLOR_RAMP_ON + keywordsDisplayNames: + - _COLOR_RAMP_ON + effectProperties: + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 15 + propertyName: _ColorRampLightingStage + displayName: Stage + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: + - + propertyKeywords: + - BeforeLighting + - AfterLighting + fullKeywordNames: + - _COLORRAMPLIGHTINGSTAGE_BEFORELIGHTING + - _COLORRAMPLIGHTINGSTAGE_AFTERLIGHTING + keywordsOp: 0 + allowReset: 0 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 16 + propertyName: _ColorRampTex + displayName: Color Ramp Tex + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 17 + propertyName: _ColorRampLuminosity + displayName: Color Ramp Luminosity + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 18 + propertyName: _ColorRampBlend + displayName: Color Ramp Blend + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 19 + propertyName: _ColorRampTiling + displayName: Tiling + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719303 + propertyIndex: 20 + propertyName: _ColorRampScrollSpeed + displayName: Scroll Speed + keywords: + - _COLOR_RAMP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 12 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719304 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: AOMAP + displayName: AO Map + group: ColorEffects + keywordPropertyIndex: 78 + keywordPropertyName: _AOMapEnabled + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _AOMAP_ON + displayName: _AOMAP_ON + keywordsDisplayNames: + - _AOMAP_ON + effectProperties: + - parentEffect: + rid: 6567500035957719304 + propertyIndex: 79 + propertyName: _AOMap + displayName: AO Map + keywords: + - _AOMAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719304 + propertyIndex: 80 + propertyName: _AOMapStrength + displayName: AO Strength + keywords: + - _AOMAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719304 + propertyIndex: 81 + propertyName: _AOContrast + displayName: AO Contrast + keywords: + - _AOMAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719304 + propertyIndex: 82 + propertyName: _AOColor + displayName: AO Color + keywords: + - _AOMAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 13 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719305 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: HIGHLIGHTS + displayName: Highlights + group: ColorEffects + keywordPropertyIndex: 83 + keywordPropertyName: _Highlights + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HIGHLIGHTS_ON + displayName: _HIGHLIGHTS_ON + keywordsDisplayNames: + - _HIGHLIGHTS_ON + effectProperties: + - parentEffect: + rid: 6567500035957719305 + propertyIndex: 84 + propertyName: _HighlightsColor + displayName: Highlights Color + keywords: + - _HIGHLIGHTS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719305 + propertyIndex: 85 + propertyName: _HighlightsStrength + displayName: Highlights Strength + keywords: + - _HIGHLIGHTS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719305 + propertyIndex: 86 + propertyName: _HighlightCutoff + displayName: Highlight Cutoff + keywords: + - _HIGHLIGHTS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719305 + propertyIndex: 87 + propertyName: _HighlightSmoothness + displayName: Highlight Smoothness + keywords: + - _HIGHLIGHTS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719305 + propertyIndex: 88 + propertyName: _HighlightOffset + displayName: Highlight Offset + keywords: + - _HIGHLIGHTS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 14 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719306 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: RIM_LIGHTING + displayName: Rim or Fresnel + group: ColorEffects + keywordPropertyIndex: 89 + keywordPropertyName: _RimLighting + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _RIM_LIGHTING_ON + displayName: _RIM_LIGHTING_ON + keywordsDisplayNames: + - _RIM_LIGHTING_ON + effectProperties: + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 90 + propertyName: _RimLightingStage + displayName: Stage + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: + - + propertyKeywords: + - BeforeLighting + - BeforeLightingLast + - AfterLighting + fullKeywordNames: + - _RIMLIGHTINGSTAGE_BEFORELIGHTING + - _RIMLIGHTINGSTAGE_BEFORELIGHTINGLAST + - _RIMLIGHTINGSTAGE_AFTERLIGHTING + keywordsOp: 0 + allowReset: 0 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 91 + propertyName: _RimColor + displayName: Rim Color + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 92 + propertyName: _RimAttenuation + displayName: Rim Attenuation + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 93 + propertyName: _MinRim + displayName: Min Rim + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 94 + propertyName: _MaxRim + displayName: Max Rim + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719306 + propertyIndex: 95 + propertyName: _RimOffset + displayName: Rim Offset + keywords: + - _RIM_LIGHTING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 15 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719307 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: GREYSCALE + displayName: Greyscale + group: ColorEffects + keywordPropertyIndex: 96 + keywordPropertyName: _Greyscale + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _GREYSCALE_ON + displayName: _GREYSCALE_ON + keywordsDisplayNames: + - _GREYSCALE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719307 + propertyIndex: 97 + propertyName: _GreyScaleStage + displayName: Stage + keywords: + - _GREYSCALE_ON + incompatibleKeywords: [] + propertyKeywords: + - BeforeLighting + - AfterLighting + fullKeywordNames: + - _GREYSCALESTAGE_BEFORELIGHTING + - _GREYSCALESTAGE_AFTERLIGHTING + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719307 + propertyIndex: 98 + propertyName: _GreyscaleLuminosity + displayName: Luminosity + keywords: + - _GREYSCALE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719307 + propertyIndex: 99 + propertyName: _GreyscaleTintColor + displayName: Greyscale Tint + keywords: + - _GREYSCALE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719307 + propertyIndex: 100 + propertyName: _GreyscaleBlending + displayName: Blending + keywords: + - _GREYSCALE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 16 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719308 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: POSTERIZE + displayName: Posterize + group: ColorEffects + keywordPropertyIndex: 101 + keywordPropertyName: _Posterize + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _POSTERIZE_ON + displayName: _POSTERIZE_ON + keywordsDisplayNames: + - _POSTERIZE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719308 + propertyIndex: 102 + propertyName: _PosterizeNumColors + displayName: Number of Colors + keywords: + - _POSTERIZE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719308 + propertyIndex: 103 + propertyName: _PosterizeGamma + displayName: Posterize Gamma + keywords: + - _POSTERIZE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 17 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719309 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: HUE_SHIFT + displayName: Hue Shift + group: ColorEffects + keywordPropertyIndex: 141 + keywordPropertyName: _HueShiftEnabled + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HUE_SHIFT_ON + displayName: _HUE_SHIFT_ON + keywordsDisplayNames: + - _HUE_SHIFT_ON + effectProperties: + - parentEffect: + rid: 6567500035957719309 + propertyIndex: 142 + propertyName: _HueShift + displayName: Hue Shift + keywords: + - _HUE_SHIFT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719309 + propertyIndex: 143 + propertyName: _HueSaturation + displayName: Saturation + keywords: + - _HUE_SHIFT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719309 + propertyIndex: 144 + propertyName: _HueBrightness + displayName: Brightness + keywords: + - _HUE_SHIFT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 18 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719310 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: EMISSION + displayName: Emission + group: ColorEffects + keywordPropertyIndex: 145 + keywordPropertyName: _EmissionEnabled + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _EMISSION_ON + displayName: _EMISSION_ON + keywordsDisplayNames: + - _EMISSION_ON + effectProperties: + - parentEffect: + rid: 6567500035957719310 + propertyIndex: 146 + propertyName: _EmissionSelfGlow + displayName: Emission Self Glow + keywords: + - _EMISSION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719310 + propertyIndex: 147 + propertyName: _EmissionColor + displayName: Emission Color + keywords: + - _EMISSION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719310 + propertyIndex: 148 + propertyName: _EmissionMap + displayName: Emission Map + keywords: + - _EMISSION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + disabledKeyword: + displayIndex: 19 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719311 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: HOLOGRAM + displayName: Hologram + group: ColorEffects + keywordPropertyIndex: 149 + keywordPropertyName: _Hologram + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HOLOGRAM_ON + displayName: _HOLOGRAM_ON + keywordsDisplayNames: + - _HOLOGRAM_ON + effectProperties: + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 150 + propertyName: _HologramColor + displayName: Hologram Color + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 151 + propertyName: _HologramLineDirection + displayName: Line Direction + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 152 + propertyName: _HologramBaseAlpha + displayName: Hologram Base Alpha + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 153 + propertyName: _HologramScrollSpeed + displayName: Hologram Scroll Speed + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 154 + propertyName: _HologramFrequency + displayName: Hologram Frequency + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 155 + propertyName: _HologramAlpha + displayName: Hologram Alpha + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 156 + propertyName: _HologramAccentSpeed + displayName: Hologram Accent Speed + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 157 + propertyName: _HologramAccentFrequency + displayName: Hologram Accent Frequency + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 158 + propertyName: _HologramAccentAlpha + displayName: Hologram Accent Alpha + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 159 + propertyName: _HologramLineCenter + displayName: Hologram Line Center + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 160 + propertyName: _HologramLineSpacing + displayName: Hologram Line Spacing + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719311 + propertyIndex: 161 + propertyName: _HologramLineSmoothness + displayName: Hologram Line Smoothness + keywords: + - _HOLOGRAM_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 20 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719312 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: MATCAP + displayName: Matcap + group: ColorEffects + keywordPropertyIndex: 162 + keywordPropertyName: _Matcap + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _MATCAP_ON + displayName: _MATCAP_ON + keywordsDisplayNames: + - _MATCAP_ON + effectProperties: + - parentEffect: + rid: 6567500035957719312 + propertyIndex: 163 + propertyName: _MatcapBlendMode + displayName: Blend Mode + keywords: + - _MATCAP_ON + incompatibleKeywords: [] + propertyKeywords: + - Multiply + - Replace + fullKeywordNames: + - _MATCAPBLENDMODE_MULTIPLY + - _MATCAPBLENDMODE_REPLACE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719312 + propertyIndex: 164 + propertyName: _MatcapTex + displayName: Matcap Tex + keywords: + - _MATCAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719312 + propertyIndex: 165 + propertyName: _MatcapIntensity + displayName: Matcap Intensity + keywords: + - _MATCAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719312 + propertyIndex: 166 + propertyName: _MatcapBlend + displayName: Matcap Blend + keywords: + - _MATCAP_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 21 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719313 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: HIT + displayName: Hit + group: ColorEffects + keywordPropertyIndex: 167 + keywordPropertyName: _Hit + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HIT_ON + displayName: _HIT_ON + keywordsDisplayNames: + - _HIT_ON + effectProperties: + - parentEffect: + rid: 6567500035957719313 + propertyIndex: 168 + propertyName: _HitColor + displayName: Hit Color + keywords: + - _HIT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719313 + propertyIndex: 169 + propertyName: _HitGlow + displayName: Hit Glow + keywords: + - _HIT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719313 + propertyIndex: 170 + propertyName: _HitBlend + displayName: Hit Blend + keywords: + - _HIT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 22 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719314 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: CONTRAST_BRIGHTNESS + displayName: Contrast and Brightness + group: ColorEffects + keywordPropertyIndex: 171 + keywordPropertyName: _ContrastBrightnessOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _CONTRAST_BRIGHTNESS_ON + displayName: _CONTRAST_BRIGHTNESS_ON + keywordsDisplayNames: + - _CONTRAST_BRIGHTNESS_ON + effectProperties: + - parentEffect: + rid: 6567500035957719314 + propertyIndex: 172 + propertyName: _Contrast + displayName: Contrast + keywords: + - _CONTRAST_BRIGHTNESS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719314 + propertyIndex: 173 + propertyName: _Brightness + displayName: Brightness + keywords: + - _CONTRAST_BRIGHTNESS_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 23 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719315 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: HEIGHT_GRADIENT + displayName: Height Gradient + group: ColorEffects + keywordPropertyIndex: 174 + keywordPropertyName: _HeightGradientOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HEIGHT_GRADIENT_ON + displayName: _HEIGHT_GRADIENT_ON + keywordsDisplayNames: + - _HEIGHT_GRADIENT_ON + effectProperties: + - parentEffect: + rid: 6567500035957719315 + propertyIndex: 175 + propertyName: _HeightGradientPositionSpace + displayName: Position Space + keywords: + - _HEIGHT_GRADIENT_ON + incompatibleKeywords: [] + propertyKeywords: + - Local + - World + fullKeywordNames: + - _HEIGHTGRADIENTPOSITIONSPACE_LOCAL + - _HEIGHTGRADIENTPOSITIONSPACE_WORLD + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719315 + propertyIndex: 176 + propertyName: _MinGradientHeight + displayName: Min Height + keywords: + - _HEIGHT_GRADIENT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719315 + propertyIndex: 177 + propertyName: _MaxGradientHeight + displayName: Max Height + keywords: + - _HEIGHT_GRADIENT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719315 + propertyIndex: 178 + propertyName: _GradientHeightColor01 + displayName: Gradient Color 01 + keywords: + - _HEIGHT_GRADIENT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719315 + propertyIndex: 179 + propertyName: _GradientHeightColor02 + displayName: Gradient Color 02 + keywords: + - _HEIGHT_GRADIENT_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 24 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719316 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: INTERSECTION_GLOW + displayName: Intersection Glow + group: ColorEffects + keywordPropertyIndex: 180 + keywordPropertyName: _IntersectionGlowOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: + - message: '*You need to set the material to Transparent mode in order to + use this effect correctly' + keywords: [] + keywords: + - keyword: _INTERSECTION_GLOW_ON + displayName: _INTERSECTION_GLOW_ON + keywordsDisplayNames: + - _INTERSECTION_GLOW_ON + effectProperties: + - parentEffect: + rid: 6567500035957719316 + propertyIndex: 181 + propertyName: _DepthGlowDist + displayName: Depth Distance + keywords: + - _INTERSECTION_GLOW_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719316 + propertyIndex: 182 + propertyName: _DepthGlowPower + displayName: Depth Power + keywords: + - _INTERSECTION_GLOW_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719316 + propertyIndex: 183 + propertyName: _DepthGlowColor + displayName: Depth Glow Color + keywords: + - _INTERSECTION_GLOW_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719316 + propertyIndex: 184 + propertyName: _DepthGlowColorIntensity + displayName: Color Intensity + keywords: + - _INTERSECTION_GLOW_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719316 + propertyIndex: 185 + propertyName: _DepthGlowGlobalIntensity + displayName: Global Intensity + keywords: + - _INTERSECTION_GLOW_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 25 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719317 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: ALBEDO_VERTEX_COLOR + displayName: Albedo From Vertex Color + group: ColorEffects + keywordPropertyIndex: 186 + keywordPropertyName: _AlbedoVertexColorOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _ALBEDO_VERTEX_COLOR_ON + displayName: _ALBEDO_VERTEX_COLOR_ON + keywordsDisplayNames: + - _ALBEDO_VERTEX_COLOR_ON + effectProperties: + - parentEffect: + rid: 6567500035957719317 + propertyIndex: 187 + propertyName: _AlbedoVertexColorMode + displayName: Mode + keywords: + - _ALBEDO_VERTEX_COLOR_ON + incompatibleKeywords: [] + propertyKeywords: + - Multiply + - Replace + fullKeywordNames: + - _ALBEDOVERTEXCOLORMODE_MULTIPLY + - _ALBEDOVERTEXCOLORMODE_REPLACE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719317 + propertyIndex: 188 + propertyName: _VertexColorBlending + displayName: Blending + keywords: + - _ALBEDO_VERTEX_COLOR_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 26 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719318 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: TRIPLANAR_MAPPING + displayName: Triplanar Mapping + group: ColorEffects + keywordPropertyIndex: 189 + keywordPropertyName: _TriplanarMappingOn + effectDrawerID: TRIPLANAR_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: SCREEN_SPACE_UV + docURL: + customMessages: [] + keywords: + - keyword: _TRIPLANAR_MAPPING_ON + displayName: _TRIPLANAR_MAPPING_ON + keywordsDisplayNames: + - _TRIPLANAR_MAPPING_ON + effectProperties: + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 190 + propertyName: _TriplanarNormalSpace + displayName: UV Space + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: + - Local + - World + fullKeywordNames: + - _TRIPLANARNORMALSPACE_LOCAL + - _TRIPLANARNORMALSPACE_WORLD + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 191 + propertyName: _TriplanarTopTex + displayName: Top Texture + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 192 + propertyName: _TriplanarTopNormalMap + displayName: Top Normal Map + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 193 + propertyName: _TopNormalStrength + displayName: Top Normal Map Strength + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 194 + propertyName: _FaceDownCutoff + displayName: Face Down Cutoff + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 195 + propertyName: _TriplanarSharpness + displayName: Sharpness + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 196 + propertyName: _TriplanarNoiseTransitionOn + displayName: Noise Transition + keywords: + - _TRIPLANAR_MAPPING_ON + incompatibleKeywords: [] + propertyKeywords: + - _TRIPLANAR_NOISE_TRANSITION_ON + fullKeywordNames: + - _TRIPLANAR_NOISE_TRANSITION_ON + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 197 + propertyName: _TriplanarNoiseTex + displayName: Noise Tex + keywords: + - _TRIPLANAR_NOISE_TRANSITION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719318 + propertyIndex: 198 + propertyName: _TriplanarTransitionPower + displayName: Transition Power + keywords: + - _TRIPLANAR_NOISE_TRANSITION_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 27 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719319 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: TEXTURE_BLENDING + displayName: Texture Blending + group: ColorEffects + keywordPropertyIndex: 199 + keywordPropertyName: _TextureBlending + effectDrawerID: TEXTURE_BLENDING_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _TEXTURE_BLENDING_ON + displayName: _TEXTURE_BLENDING_ON + keywordsDisplayNames: + - _TEXTURE_BLENDING_ON + effectProperties: + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 200 + propertyName: _TextureBlendingSource + displayName: Source + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: + - VertexColor + - Texture + fullKeywordNames: + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + - _TEXTUREBLENDINGSOURCE_TEXTURE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 201 + propertyName: _TexBlendingMask + displayName: Texture Blending Mask + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 202 + propertyName: _BlendingMaskCutoffG + displayName: Cutoff (G) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 203 + propertyName: _BlendingMaskSmoothnessG + displayName: Smoothness (G) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 204 + propertyName: _BlendingMaskCutoffB + displayName: Cutoff (B) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 205 + propertyName: _BlendingMaskSmoothnessB + displayName: Smoothness (B) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 206 + propertyName: _BlendingMaskCutoffWhite + displayName: Cutoff (White) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 207 + propertyName: _BlendingMaskSmoothnessWhite + displayName: Smoothness (White) + keywords: + - _TEXTUREBLENDINGSOURCE_TEXTURE + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 208 + propertyName: _TextureBlendingMode + displayName: Blending Mode + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: + - RGB + - BlackAndWhite + fullKeywordNames: + - _TEXTUREBLENDINGMODE_RGB + - _TEXTUREBLENDINGMODE_BLACKANDWHITE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 209 + propertyName: _BlendingTextureG + displayName: Blending Texture (G) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 210 + propertyName: _BlendingTextureB + displayName: Blending Texture (B) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 211 + propertyName: _BlendingTextureWhite + displayName: Blending Texture (White) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 212 + propertyName: _BlendingNormalMapG + displayName: Blending Normal Map (G) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 213 + propertyName: _BlendingNormalMapB + displayName: Blending Normal Map (B) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719319 + propertyIndex: 214 + propertyName: _BlendingNormalMapWhite + displayName: Blending Normal Map (White) + keywords: + - _TEXTURE_BLENDING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 28 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719320 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: SUBSURFACE_SCATTERING + displayName: Fake Subsurface Scattering + group: ColorEffects + keywordPropertyIndex: 216 + keywordPropertyName: _SubsurfaceScattering + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _SUBSURFACE_SCATTERING_ON + displayName: _SUBSURFACE_SCATTERING_ON + keywordsDisplayNames: + - _SUBSURFACE_SCATTERING_ON + effectProperties: + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 217 + propertyName: _NormalInfluence + displayName: Normal Influence + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 218 + propertyName: _SSSPower + displayName: SSS Power + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 219 + propertyName: _SSSFrontPower + displayName: SSS Front Power + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 220 + propertyName: _SSSFrontAtten + displayName: SSS Front Atten + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 221 + propertyName: _SSSAtten + displayName: SSS General Atten + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 222 + propertyName: _SSSColor + displayName: SSS Color + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719320 + propertyIndex: 223 + propertyName: _SSSMap + displayName: SSS Map + keywords: + - _SUBSURFACE_SCATTERING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + disabledKeyword: + displayIndex: 30 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719321 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: ALPHA_CUTOFF + displayName: Alpha Cutoff + group: AlphaEffects + keywordPropertyIndex: 224 + keywordPropertyName: _AlphaCutoffOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _ALPHA_CUTOFF_ON + displayName: _ALPHA_CUTOFF_ON + keywordsDisplayNames: + - _ALPHA_CUTOFF_ON + effectProperties: + - parentEffect: + rid: 6567500035957719321 + propertyIndex: 225 + propertyName: _AlphaCutoffValue + displayName: Cutoff Value + keywords: + - _ALPHA_CUTOFF_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 31 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719322 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: FADE + displayName: Fade + group: AlphaEffects + keywordPropertyIndex: 226 + keywordPropertyName: _FadeOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _FADE_ON + displayName: _FADE_ON + keywordsDisplayNames: + - _FADE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 227 + propertyName: _FadeTex + displayName: Fade Tex + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 228 + propertyName: _FadeUVSet + displayName: UV Set + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: + - UV1 + - UV2 + - WORLD_SPACE + fullKeywordNames: + - _FADEUVSET_UV1 + - _FADEUVSET_UV2 + - _FADEUVSET_WORLD_SPACE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 229 + propertyName: _FadeAmount + displayName: Fade Amount + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 230 + propertyName: _FadePower + displayName: Fade Power + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 231 + propertyName: _FadeTransition + displayName: Fade Transition + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 232 + propertyName: _FadeBurnOn + displayName: Use Fade Burn Color? + keywords: + - _FADE_ON + incompatibleKeywords: [] + propertyKeywords: + - _FADE_BURN_ON + fullKeywordNames: + - _FADE_BURN_ON + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 233 + propertyName: _FadeBurnColor + displayName: Fade Burn Color + keywords: + - _FADE_BURN_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719322 + propertyIndex: 234 + propertyName: _FadeBurnWidth + displayName: Fade Burn Width + keywords: + - _FADE_BURN_ON + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 32 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719323 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: INTERSECTION_FADE + displayName: Intersection Fade + group: AlphaEffects + keywordPropertyIndex: 235 + keywordPropertyName: _IntersectionFadeOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: + - message: '*You need to set the material to Transparent mode in order to + use this effect correctly' + keywords: [] + keywords: + - keyword: _INTERSECTION_FADE_ON + displayName: _INTERSECTION_FADE_ON + keywordsDisplayNames: + - _INTERSECTION_FADE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719323 + propertyIndex: 236 + propertyName: _IntersectionFadeFactor + displayName: Intersection Fade Factor + keywords: + - _INTERSECTION_FADE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 33 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719324 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: FADE_BY_CAM_DISTANCE + displayName: Fade By Cam Distance + group: AlphaEffects + keywordPropertyIndex: 238 + keywordPropertyName: _FadeByCamDistanceOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _FADE_BY_CAM_DISTANCE_ON + displayName: _FADE_BY_CAM_DISTANCE_ON + keywordsDisplayNames: + - _FADE_BY_CAM_DISTANCE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719324 + propertyIndex: 239 + propertyName: _NearFade + displayName: Near Fade + keywords: + - _FADE_BY_CAM_DISTANCE_ON + incompatibleKeywords: [] + propertyKeywords: + - _FADE_BY_CAM_DISTANCE_NEAR_FADE + fullKeywordNames: + - _FADE_BY_CAM_DISTANCE_NEAR_FADE + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719324 + propertyIndex: 240 + propertyName: _MinDistanceToFade + displayName: Min Distance + keywords: + - _FADE_BY_CAM_DISTANCE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719324 + propertyIndex: 241 + propertyName: _MaxDistanceToFade + displayName: Max Distance + keywords: + - _FADE_BY_CAM_DISTANCE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 35 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719325 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: DITHER + displayName: Dither + group: AlphaEffects + keywordPropertyIndex: 242 + keywordPropertyName: _DitherOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _DITHER_ON + displayName: _DITHER_ON + keywordsDisplayNames: + - _DITHER_ON + effectProperties: + - parentEffect: + rid: 6567500035957719325 + propertyIndex: 243 + propertyName: _DitherScale + displayName: Scale + keywords: + - _DITHER_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 36 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719326 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: VERTEX_SHAKE + displayName: Vertex Shake + group: MeshEffects + keywordPropertyIndex: 112 + keywordPropertyName: _VertexShakeOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _VERTEX_SHAKE_ON + displayName: _VERTEX_SHAKE_ON + keywordsDisplayNames: + - _VERTEX_SHAKE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719326 + propertyIndex: 113 + propertyName: _ShakeSpeed + displayName: Speed + keywords: + - _VERTEX_SHAKE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719326 + propertyIndex: 114 + propertyName: _ShakeSpeedMult + displayName: Shake Mult + keywords: + - _VERTEX_SHAKE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719326 + propertyIndex: 115 + propertyName: _ShakeMaxDisplacement + displayName: Shake Max Displacement + keywords: + - _VERTEX_SHAKE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719326 + propertyIndex: 116 + propertyName: _ShakeBlend + displayName: Shake Blend + keywords: + - _VERTEX_SHAKE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 37 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719327 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: VERTEX_INFLATE + displayName: Vertex Inflate + group: MeshEffects + keywordPropertyIndex: 117 + keywordPropertyName: _VertexInflate + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _VERTEX_INFLATE_ON + displayName: _VERTEX_INFLATE_ON + keywordsDisplayNames: + - _VERTEX_INFLATE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719327 + propertyIndex: 118 + propertyName: _MinInflate + displayName: Min Inflate + keywords: + - _VERTEX_INFLATE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719327 + propertyIndex: 119 + propertyName: _MaxInflate + displayName: Max Inflate + keywords: + - _VERTEX_INFLATE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719327 + propertyIndex: 120 + propertyName: _InflateBlend + displayName: Inflate blend + keywords: + - _VERTEX_INFLATE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 38 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719328 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: VERTEX_DISTORTION + displayName: Vertex Distortion + group: MeshEffects + keywordPropertyIndex: 121 + keywordPropertyName: _VertexDistortionOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _VERTEX_DISTORTION_ON + displayName: _VERTEX_DISTORTION_ON + keywordsDisplayNames: + - _VERTEX_DISTORTION_ON + effectProperties: + - parentEffect: + rid: 6567500035957719328 + propertyIndex: 122 + propertyName: _VertexDistortionNoiseTex + displayName: Noise Tex + keywords: + - _VERTEX_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719328 + propertyIndex: 123 + propertyName: _VertexDistortionAmount + displayName: Distortion Amount + keywords: + - _VERTEX_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719328 + propertyIndex: 124 + propertyName: _VertexDistortionNoiseSpeedX + displayName: Scroll Speed X + keywords: + - _VERTEX_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719328 + propertyIndex: 125 + propertyName: _VertexDistortionNoiseSpeedY + displayName: Scroll Speed Y + keywords: + - _VERTEX_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 39 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719329 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: VOXELIZE + displayName: Voxelize + group: MeshEffects + keywordPropertyIndex: 126 + keywordPropertyName: _Voxelize + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _VOXELIZE_ON + displayName: _VOXELIZE_ON + keywordsDisplayNames: + - _VOXELIZE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719329 + propertyIndex: 127 + propertyName: _VoxelSize + displayName: Voxel Size + keywords: + - _VOXELIZE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719329 + propertyIndex: 128 + propertyName: _VoxelBlend + displayName: Blend Amount + keywords: + - _VOXELIZE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 40 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719330 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: GLITCH + displayName: Glitch + group: MeshEffects + keywordPropertyIndex: 129 + keywordPropertyName: _Glitch + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _GLITCH_ON + displayName: _GLITCH_ON + keywordsDisplayNames: + - _GLITCH_ON + effectProperties: + - parentEffect: + rid: 6567500035957719330 + propertyIndex: 130 + propertyName: _GlitchTiling + displayName: Glitch Tiling + keywords: + - _GLITCH_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719330 + propertyIndex: 131 + propertyName: _GlitchAmount + displayName: Glitch Amount + keywords: + - _GLITCH_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719330 + propertyIndex: 132 + propertyName: _GlitchOffset + displayName: Glitch Offset + keywords: + - _GLITCH_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 1 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719330 + propertyIndex: 133 + propertyName: _GlitchSpeed + displayName: Glitch Speed + keywords: + - _GLITCH_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719330 + propertyIndex: 134 + propertyName: _GlitchWorldSpace + displayName: Use World Space + keywords: + - _GLITCH_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 41 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719331 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: WIND + displayName: Wind + group: MeshEffects + keywordPropertyIndex: 136 + keywordPropertyName: _WindOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/wind-effect-and-wind-controller + customMessages: + - message: "*You need to use WindController.cs component\n in order to use + this effect." + keywords: [] + keywords: + - keyword: _WIND_ON + displayName: _WIND_ON + keywordsDisplayNames: + - _WIND_ON + effectProperties: + - parentEffect: + rid: 6567500035957719331 + propertyIndex: 137 + propertyName: _WindAttenuation + displayName: Attenuation + keywords: + - _WIND_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719331 + propertyIndex: 138 + propertyName: _UseVerticalMask + displayName: Use Vertical Mask? + keywords: + - _WIND_ON + incompatibleKeywords: [] + propertyKeywords: + - _USE_WIND_VERTICAL_MASK + fullKeywordNames: + - _USE_WIND_VERTICAL_MASK + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719331 + propertyIndex: 139 + propertyName: _WindVerticalMaskMinY + displayName: Min Y + keywords: + - _USE_WIND_VERTICAL_MASK + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719331 + propertyIndex: 140 + propertyName: _WindVerticalMaskMaxY + displayName: Max Y + keywords: + - _USE_WIND_VERTICAL_MASK + incompatibleKeywords: + - + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 43 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719332 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: SCROLL_TEXTURE + displayName: Scroll Texture + group: UVEffects + keywordPropertyIndex: 62 + keywordPropertyName: _ScrollTextureOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _SCROLL_TEXTURE_ON + displayName: _SCROLL_TEXTURE_ON + keywordsDisplayNames: + - _SCROLL_TEXTURE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719332 + propertyIndex: 63 + propertyName: _ScrollTextureX + displayName: Scroll X + keywords: + - _SCROLL_TEXTURE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719332 + propertyIndex: 64 + propertyName: _ScrollTextureY + displayName: Scroll Y + keywords: + - _SCROLL_TEXTURE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 44 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719333 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: SCREEN_SPACE_UV + displayName: Screen Space UV + group: UVEffects + keywordPropertyIndex: 65 + keywordPropertyName: _ScreenSpaceUVOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: TRIPLANAR_MAPPING + docURL: + customMessages: [] + keywords: + - keyword: _SCREEN_SPACE_UV_ON + displayName: _SCREEN_SPACE_UV_ON + keywordsDisplayNames: + - _SCREEN_SPACE_UV_ON + effectProperties: + - parentEffect: + rid: 6567500035957719333 + propertyIndex: 66 + propertyName: _ScaleWithCameraDistance + displayName: Scale with camera distance + keywords: + - _SCREEN_SPACE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 45 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719334 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: PIXELATE + displayName: Pixelate + group: UVEffects + keywordPropertyIndex: 67 + keywordPropertyName: _Pixelate + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _PIXELATE_ON + displayName: _PIXELATE_ON + keywordsDisplayNames: + - _PIXELATE_ON + effectProperties: + - parentEffect: + rid: 6567500035957719334 + propertyIndex: 68 + propertyName: _PixelateSize + displayName: Pixelate Size + keywords: + - _PIXELATE_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 46 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719335 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: STOCHASTIC_SAMPLING + displayName: Stochastic Sampling + group: UVEffects + keywordPropertyIndex: 69 + keywordPropertyName: _StochasticSampling + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _STOCHASTIC_SAMPLING_ON + displayName: _STOCHASTIC_SAMPLING_ON + keywordsDisplayNames: + - _STOCHASTIC_SAMPLING_ON + effectProperties: + - parentEffect: + rid: 6567500035957719335 + propertyIndex: 70 + propertyName: _StochasticScale + displayName: Grid Scale + keywords: + - _STOCHASTIC_SAMPLING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719335 + propertyIndex: 71 + propertyName: _StochasticSkew + displayName: Grid Skew + keywords: + - _STOCHASTIC_SAMPLING_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 47 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719336 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: WAVE_UV + displayName: Wave UV On + group: UVEffects + keywordPropertyIndex: 72 + keywordPropertyName: _WaveUVOn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _WAVE_UV_ON + displayName: _WAVE_UV_ON + keywordsDisplayNames: + - _WAVE_UV_ON + effectProperties: + - parentEffect: + rid: 6567500035957719336 + propertyIndex: 73 + propertyName: _WaveAmount + displayName: Wave Amount + keywords: + - _WAVE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719336 + propertyIndex: 74 + propertyName: _WaveSpeed + displayName: Wave Speed + keywords: + - _WAVE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719336 + propertyIndex: 75 + propertyName: _WaveStrength + displayName: Wave Strength + keywords: + - _WAVE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719336 + propertyIndex: 76 + propertyName: _WaveX + displayName: Wave X Axis + keywords: + - _WAVE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719336 + propertyIndex: 77 + propertyName: _WaveY + displayName: Wave Y Axis + keywords: + - _WAVE_UV_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 48 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719337 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: HAND_DRAWN + displayName: Hand Drawn + group: UVEffects + keywordPropertyIndex: 104 + keywordPropertyName: _HandDrawn + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _HAND_DRAWN_ON + displayName: _HAND_DRAWN_ON + keywordsDisplayNames: + - _HAND_DRAWN_ON + effectProperties: + - parentEffect: + rid: 6567500035957719337 + propertyIndex: 105 + propertyName: _HandDrawnAmount + displayName: Hand Drawn Amount + keywords: + - _HAND_DRAWN_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719337 + propertyIndex: 106 + propertyName: _HandDrawnSpeed + displayName: Hand Drawn Speed + keywords: + - _HAND_DRAWN_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 49 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719338 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: UV_DISTORTION + displayName: Distortion + group: UVEffects + keywordPropertyIndex: 107 + keywordPropertyName: _UVDistortion + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: [] + keywords: + - keyword: _UV_DISTORTION_ON + displayName: _UV_DISTORTION_ON + keywordsDisplayNames: + - _UV_DISTORTION_ON + effectProperties: + - parentEffect: + rid: 6567500035957719338 + propertyIndex: 108 + propertyName: _DistortTex + displayName: Distortion Texture + keywords: + - _UV_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 4 + isHDR: 0 + hasTilingAndOffset: 1 + - parentEffect: + rid: 6567500035957719338 + propertyIndex: 109 + propertyName: _DistortAmount + displayName: Distortion Amount + keywords: + - _UV_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719338 + propertyIndex: 110 + propertyName: _DistortTexXSpeed + displayName: Scroll speed X + keywords: + - _UV_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719338 + propertyIndex: 111 + propertyName: _DistortTexYSpeed + displayName: Scroll speed Y + keywords: + - _UV_DISTORTION_ON + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 3 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 50 + effectConfigType: 0 + extraPasses: + - rid: 6567500035957719339 + type: {class: AllIn13DEffectConfig, ns: AllIn13DShader, asm: AllIn13DShaderAssemebly.Editor} + data: + effectName: OUTLINETYPE + displayName: Outline Type + group: OtherEffects + keywordPropertyIndex: 244 + keywordPropertyName: _OutlineType + effectDrawerID: GENERAL_EFFECT_DRAWER + dependentOnEffect: + incompatibleWithEffectID: + docURL: + customMessages: + - message: '*If the material is transparent, you need to enable Depth Write. + Otherwise, the mesh will look completely black + +' + keywords: + - _OUTLINETYPE_SIMPLE + - _OUTLINETYPE_CONSTANT + - _OUTLINETYPE_FADEWITHDISTANCE + keywords: + - keyword: _OUTLINETYPE_NONE + displayName: None + - keyword: _OUTLINETYPE_SIMPLE + displayName: Simple + - keyword: _OUTLINETYPE_CONSTANT + displayName: Constant + - keyword: _OUTLINETYPE_FADEWITHDISTANCE + displayName: FadeWithDistance + keywordsDisplayNames: + - None + - Simple + - Constant + - FadeWithDistance + effectProperties: + - parentEffect: + rid: 6567500035957719339 + propertyIndex: 246 + propertyName: _OutlineColor + displayName: Outline Color + keywords: + - _OUTLINETYPE_SIMPLE + - _OUTLINETYPE_CONSTANT + - _OUTLINETYPE_FADEWITHDISTANCE + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 0 + isHDR: 1 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719339 + propertyIndex: 247 + propertyName: _MaxCameraDistance + displayName: Max Camera Distance + keywords: + - _OUTLINETYPE_CONSTANT + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719339 + propertyIndex: 248 + propertyName: _MaxFadeDistance + displayName: Max Fade Distance + keywords: + - _OUTLINETYPE_FADEWITHDISTANCE + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719339 + propertyIndex: 249 + propertyName: _OutlineThickness + displayName: Outline Thickness + keywords: + - _OUTLINETYPE_SIMPLE + - _OUTLINETYPE_CONSTANT + - _OUTLINETYPE_FADEWITHDISTANCE + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + - parentEffect: + rid: 6567500035957719339 + propertyIndex: 250 + propertyName: _OutlineMode + displayName: Outline Mode + keywords: + - _OUTLINETYPE_SIMPLE + - _OUTLINETYPE_CONSTANT + - _OUTLINETYPE_FADEWITHDISTANCE + incompatibleKeywords: [] + propertyKeywords: [] + fullKeywordNames: [] + keywordsOp: 0 + allowReset: 1 + shaderPropertyType: 2 + isHDR: 0 + hasTilingAndOffset: 0 + disabledKeyword: + displayIndex: 51 + effectConfigType: 1 + extraPasses: 01000000 diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/PropertiesConfigCollection.asset.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/PropertiesConfigCollection.asset.meta new file mode 100644 index 0000000..fe3d7cd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/PropertiesConfigCollection.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 454d61b10e9ed8d4a83ae4509ebcb1a5 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/URPSettingsUserPref.asset b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/URPSettingsUserPref.asset new file mode 100644 index 0000000..9dfc09f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/URPSettingsUserPref.asset @@ -0,0 +1,45 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 18225d53cd7719c49b6df4340a1549ff, type: 3} + m_Name: URPSettingsUserPref + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.URPSettingsUserPref + preferences: + - id: ALLIN1_GPU_INSTANCING_SUPPORT + enabled: 1 + - id: ALLIN1_DOTS_INSTANCING_SUPPORT + enabled: 0 + - id: ALLIN1_FOG_SUPPORT + enabled: 1 + - id: ALLIN1_LIGHTMAPS_SUPPORT + enabled: 1 + - id: ALLIN1_ADDITIONAL_LIGHTS_SUPPORT + enabled: 1 + - id: ALLIN1_CAST_SHADOWS_SUPPORT + enabled: 1 + - id: ALLIN1_SHADOW_MASK_SUPPORT + enabled: 1 + - id: ALLIN1_FORWARD_PLUS_SUPPORT_UNITY6 + enabled: 1 + - id: ALLIN1_REFLECTIONS_PROBES_SUPPORT_UNITY6 + enabled: 0 + - id: ALLIN1_ADAPTATIVE_PROBE_VOLUMES_UNITY6 + enabled: 1 + - id: ALLIN1_SSO_SUPPORT + enabled: 1 + - id: ALLIN1_LIGHT_LAYERS_SUPPORT + enabled: 0 + - id: ALLIN1_DECALS_SUPPORT + enabled: 0 + - id: ALLIN1_LIGHT_COOKIES_SUPPORT + enabled: 0 + - id: ALLIN1_LODCROSSFADE_SUPPORT + enabled: 0 diff --git a/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/URPSettingsUserPref.asset.meta b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/URPSettingsUserPref.asset.meta new file mode 100644 index 0000000..29f7593 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/AllIn3DShaderConfig/URPSettingsUserPref.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 132a4a2cab34542418073815edcd22de +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures.meta new file mode 100644 index 0000000..883e694 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a9f08480a6448db49a0c7a23e92ff7d5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefault.png new file mode 100644 index 0000000..0136c65 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefault.png.meta new file mode 100644 index 0000000..c6f7687 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: f96e2c3fa17668c4fa41974c62843999 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefaultNormal.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefaultNormal.png new file mode 100644 index 0000000..35cba05 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefaultNormal.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefaultNormal.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefaultNormal.png.meta new file mode 100644 index 0000000..0c943ed --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefaultNormal.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 14a7fe5d6aacb9a419447430a60ade70 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/DirtDefaultNormal.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/GameboyRampDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/GameboyRampDefault.png new file mode 100644 index 0000000..16a5b07 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/GameboyRampDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/GameboyRampDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/GameboyRampDefault.png.meta new file mode 100644 index 0000000..9fd2180 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/GameboyRampDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 99b6592afee2790429156fef1dc9ba44 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 1 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/GameboyRampDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassDefault.png new file mode 100644 index 0000000..8eb9974 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassDefault.png.meta new file mode 100644 index 0000000..4b515bc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 2af6ba1567607124eb61349fa044375b +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/GrassDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassNormalsDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassNormalsDefault.png new file mode 100644 index 0000000..1fca316 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassNormalsDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassNormalsDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassNormalsDefault.png.meta new file mode 100644 index 0000000..1f01974 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/GrassNormalsDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 8175cba73bf87af41aeba7bbd2f3c4cd +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 1 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/GrassNormalsDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/GridDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/GridDefault.png new file mode 100644 index 0000000..727bedf Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/GridDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/GridDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/GridDefault.png.meta new file mode 100644 index 0000000..6c1e94d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/GridDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: a26b9f1a12d33184ab5e89d304e441ad +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/GridDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/MatcapDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/MatcapDefault.png new file mode 100644 index 0000000..740b213 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/MatcapDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/MatcapDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/MatcapDefault.png.meta new file mode 100644 index 0000000..a7d1c4c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/MatcapDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: cf3a2315564d4de4eb8601b697dea358 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/MatcapDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/NoiseTextureDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/NoiseTextureDefault.png new file mode 100644 index 0000000..61f00ef Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/NoiseTextureDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/NoiseTextureDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/NoiseTextureDefault.png.meta new file mode 100644 index 0000000..9926384 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/NoiseTextureDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: fcb69fdadf254834880fe3c443965278 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 1 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/NoiseTextureDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/NormalMapDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/NormalMapDefault.png new file mode 100644 index 0000000..98afc6d Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/NormalMapDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/NormalMapDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/NormalMapDefault.png.meta new file mode 100644 index 0000000..01f0d7b --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/NormalMapDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 120df76dc2d17ed4cb2d4b8b08292ed9 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 1 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/NormalMapDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/RgbNoiseDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/RgbNoiseDefault.png new file mode 100644 index 0000000..7eec89c Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/RgbNoiseDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/RgbNoiseDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/RgbNoiseDefault.png.meta new file mode 100644 index 0000000..7c727f8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/RgbNoiseDefault.png.meta @@ -0,0 +1,118 @@ +fileFormatVersion: 2 +guid: 5a775794f8704ba4385b9c92cf9f1224 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/RgbNoiseDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallDefault.png new file mode 100644 index 0000000..5764836 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallDefault.png.meta new file mode 100644 index 0000000..90efda1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: f39690d17007ab242928cd91e5a530a6 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 1 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallNormalsDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallNormalsDefault.png new file mode 100644 index 0000000..43fd7d1 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallNormalsDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallNormalsDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallNormalsDefault.png.meta new file mode 100644 index 0000000..60176d5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallNormalsDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 6246e3fe4a63c1f4f9acec9623576fc7 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 1 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/StoneWallNormalsDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/ToonRampDefault.png b/Assets/Plugins/AllIn13DShader/DefaultTextures/ToonRampDefault.png new file mode 100644 index 0000000..edb802a Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/DefaultTextures/ToonRampDefault.png differ diff --git a/Assets/Plugins/AllIn13DShader/DefaultTextures/ToonRampDefault.png.meta b/Assets/Plugins/AllIn13DShader/DefaultTextures/ToonRampDefault.png.meta new file mode 100644 index 0000000..e24edbe --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/DefaultTextures/ToonRampDefault.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 339398f75cfa2714d93579662d08ec9a +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/DefaultTextures/ToonRampDefault.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor.meta b/Assets/Plugins/AllIn13DShader/Editor.meta new file mode 100644 index 0000000..193f30c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 86d876946a58b724081dea35a6960628 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/AbstractMaterialInfo.cs b/Assets/Plugins/AllIn13DShader/Editor/AbstractMaterialInfo.cs new file mode 100644 index 0000000..9d8fe13 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/AbstractMaterialInfo.cs @@ -0,0 +1,100 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public abstract class AbstractMaterialInfo + { + public string[] enabledKeywords; + public Material mat; + + public AbstractMaterialInfo(Material mat) + { + this.enabledKeywords = new string[0]; + this.mat = mat; + } + + public abstract void RefreshKeywords(); + + public abstract void EnableKeyword(string keyword); + + public abstract void DisableKeyword(string keyword); + + public abstract bool IsShaderVariant(); + + public bool IsKeywordEnabled(string keyword) + { + bool res = false; + + for (int i = 0; i < enabledKeywords.Length; i++) + { + if (enabledKeywords[i] == keyword) + { + res = true; + break; + } + } + + return res; + } + + public int GetEnabledKeywordIndexByEffect(AllIn13DEffectConfig effectConfig) + { + int res = -1; + for (int i = 0; i < enabledKeywords.Length; i++) + { + res = effectConfig.GetKeywordIndex(enabledKeywords[i]); + if(res >= 0) + { + break; + } + } + + return res; + } + + public int GetEnabledKeywordIndexByEffectProperty(EffectProperty effectProperty) + { + int res = -1; + + if(effectProperty.IsEnumProperty() || effectProperty.IsToggleProperty()) + { + for (int i = 0; i < enabledKeywords.Length; i++) + { + for (int j = 0; j < effectProperty.fullKeywordNames.Length; j++) + { + if (effectProperty.fullKeywordNames[j] == enabledKeywords[i]) + { + res = j; + break; + } + } + + if(res >= 0) + { + break; + } + } + } + + return res; + } + + public static AbstractMaterialInfo CreateInstance(Material mat) + { + EffectsProfileCollection effectsProfileCollection = GlobalConfiguration.instance.effectsProfileCollection; + EffectsProfile effectsProfile = effectsProfileCollection.FindEffectProfileByShader(mat.shader); + + AbstractMaterialInfo res = null; + if (effectsProfile == null) + { + res = new CommonMaterialInfo(mat); + } + else + { + res = new EffectProfileMaterialInfo(effectsProfile, mat); + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/AbstractMaterialInfo.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/AbstractMaterialInfo.cs.meta new file mode 100644 index 0000000..6b1bf97 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/AbstractMaterialInfo.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 695b6880e2c7f3746be8b2dfaff26022 +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/AbstractMaterialInfo.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/AllIn13DEffectConfig.cs b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DEffectConfig.cs new file mode 100644 index 0000000..b9f8d4c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DEffectConfig.cs @@ -0,0 +1,501 @@ +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; +using UnityEngine.Rendering; +using static AllIn13DShader.EffectsExtraData; + +namespace AllIn13DShader +{ + [System.Serializable] + public class AllIn13DEffectConfig + { + public string effectName; + public string displayName; + public string group; + + public int keywordPropertyIndex; + public string keywordPropertyName; + + public string effectDrawerID; + public string dependentOnEffect; + public string incompatibleWithEffectID; + public string docURL; + public MessageByKeywords[] customMessages; + + //public List keywords; + public List keywords; + public string[] keywordsDisplayNames; + public List effectProperties; + + public string disabledKeyword; + + public int displayIndex; + + public EffectConfigType effectConfigType; + public AllIn13DPassType[] extraPasses; + + public AllIn13DEffectConfig( + string displayName, string propertyName, int propertyIndex, EffectConfigType effectConfigType, + EffectAttributeData data, EffectsExtraData effectsExtraData, int displayIndex) + { + this.displayName = displayName; + this.keywordPropertyName = propertyName; + this.keywordPropertyIndex = propertyIndex; + this.effectConfigType = effectConfigType; + + this.effectName = data.effectID; + this.group = data.groupID; + this.effectDrawerID = data.drawerID; + this.dependentOnEffect = data.dependentEffectID; + this.incompatibleWithEffectID = data.incompatibleWithEffectID; + + EffectsExtraData.ExtraData extraData = effectsExtraData.GetExtraDataByEffectID(effectName); + if(extraData != null) + { + this.docURL = extraData.docURL; + this.customMessages = extraData.customMessages; + } + + this.keywords = new List(); + this.effectProperties = new List(); + this.keywordsDisplayNames = new string[0]; + this.extraPasses = new AllIn13DPassType[0]; + + for(int i = 0; i < data.extraPasses.Length; i++) + { + AllIn13DPassType passType; + Enum.TryParse(data.extraPasses[i], out passType); + + ArrayUtility.Add(ref extraPasses, passType); + } + + this.displayIndex = displayIndex; + } + + public void AddKeyword(EffectKeywordData kw) + { + keywords.Add(kw); + } + + public void AddKeywords(EffectKeywordData[] kws) + { + keywords.AddRange(kws); + } + + public void Setup() + { + for(int i = 0; i < keywords.Count; i++) + { + ArrayUtility.Add(ref keywordsDisplayNames, keywords[i].displayName); + } + } + + public EffectProperty FindEffectPropertyByIndex(int propertyIndex) + { + EffectProperty res = null; + + for (int i = 0; i < effectProperties.Count; i++) + { + if (effectProperties[i].propertyIndex == propertyIndex) + { + res = effectProperties[i]; + break; + } + } + + return res; + } + + public EffectProperty FindEffectPropertyByName(string propertyName) + { + EffectProperty res = null; + + for(int i = 0; i < effectProperties.Count; i++) + { + if (effectProperties[i].propertyName == propertyName) + { + res = effectProperties[i]; + break; + } + } + + return res; + } + + public EffectProperty CreateEffectProperty(int propertyIndex, string propertyName, string displayName, + ShaderPropertyType shaderPropertyType, ShaderPropertyFlags shaderPropertyFlags, + EffectPropertyAttributeData data) + { + EffectProperty res = new EffectProperty(this, propertyIndex, propertyName, displayName, + data.keywordsOp, data.allowReset, shaderPropertyType, shaderPropertyFlags); + effectProperties.Add(res); + + for (int i = 0; i < data.keywords.Count; i++) + { + res.AddKeyword(data.keywords[i]); + } + + for(int i = 0; i < data.incompatibleWithKws.Count; i++) + { + res.AddIncompatibleKeyword(data.incompatibleWithKws[i]); + } + + res.AddPropertyKeywords(data.propertyKeywords); + + return res; + } + + public string GetCustomMessage(AbstractMaterialInfo[] targetMatInfos) + { + string res = string.Empty; + if(targetMatInfos.Length == 1) + { + res = GetCustomMessage(targetMatInfos[0]); + } + return res; + } + + public string GetCustomMessage(AbstractMaterialInfo targetMatInfo) + { + string res = string.Empty; + + if(customMessages != null && customMessages.Length > 0) + { + for(int i = 0; i < customMessages.Length; i++) + { + MessageByKeywords customMessage = customMessages[i]; + + if (customMessage.IsMessageEnabled(targetMatInfo)) + { + res = customMessage.message; + break; + } + } + } + + return res; + } + + public static bool IsEffectAvailable(AllIn13DEffectConfig effectConfig, AllIn13DShaderInspectorReferences references) + { + bool res = true; + bool isShaderVariant = references.IsShaderVariant(); + + if (isShaderVariant) + { + for (int i = 0; i < references.targetMatInfos.Length; i++) + { + AbstractMaterialInfo matInfo = references.targetMatInfos[i]; + res = res && AllIn13DEffectConfig.IsEffectEnabled(effectConfig, matInfo); + } + } + + return res; + } + + public static bool IsEffectEnabled(AllIn13DEffectConfig effectConfig, AllIn13DShaderInspectorReferences references) + { + int selectedIndex = 0; + return IsEffectEnabled(effectConfig, ref selectedIndex, references); + } + + public static bool IsEffectEnabled(AllIn13DEffectConfig effectConfig, AbstractMaterialInfo targetMatInfo) + { + int selectedIndex = 0; + return IsEffectEnabled(effectConfig, ref selectedIndex, targetMatInfo); + } + + public static bool IsEffectEnabled(AllIn13DEffectConfig effectConfig, ref int selectedIndex, AllIn13DShaderInspectorReferences references) + { + bool res = true; + for (int i = 0; i < references.targetMatInfos.Length; i++) + { + res = res && IsEffectEnabled(effectConfig, ref selectedIndex, references.targetMatInfos[i]); + } + + return res; + } + + public bool AreDependenciesMet(PropertiesConfig propertiesConfig, AbstractMaterialInfo targetMatInfo) + { + bool res = true; + + if (!string.IsNullOrEmpty(dependentOnEffect)) + { + AllIn13DEffectConfig dependentEffect = propertiesConfig.FindEffectConfigByID(dependentOnEffect); + res = res && IsEffectEnabled(dependentEffect, targetMatInfo); + } + + return res; + } + + public static bool IsEffectEnabled(AllIn13DEffectConfig effectConfig, ref int selectedIndex, AbstractMaterialInfo targetMatInfo) + { + selectedIndex = 0; + + bool res = false; + + if (effectConfig.keywords.Count == 1) + { + if (targetMatInfo.IsKeywordEnabled(effectConfig.keywords[0].keyword)) + { + res = true; + selectedIndex = 0; + } + } + else + { + for (int i = 0; i < effectConfig.keywords.Count; i++) + { + string keywordToCheck = effectConfig.keywords[i].keyword; + + bool isNoneOption = effectConfig.keywordsDisplayNames[i] == Constants.DISABLED_ENUM_OPTION_STR; + if (targetMatInfo.IsKeywordEnabled(keywordToCheck) && !isNoneOption) + { + res = true; + selectedIndex = i; + break; + } + } + } + + + return res; + } + + public static bool IsEffectPropertyEnabled(EffectProperty effectProperty, ref int selectedIndex, string[] enabledKeywords) + { + bool res = false; + + if (effectProperty.fullKeywordNames.Length == 1) + { + if (ArrayUtility.Contains(enabledKeywords, effectProperty.fullKeywordNames[0])) + { + res = true; + selectedIndex = 0; + } + } + else + { + for (int i = 0; i < effectProperty.fullKeywordNames.Length; i++) + { + if (ArrayUtility.Contains(enabledKeywords, effectProperty.fullKeywordNames[i])) + { + res = true; + selectedIndex = i; + break; + } + } + } + + return res; + } + + public static bool IsEffectPropertyEnabled(EffectProperty effectProperty, ref int selectedIndex, AbstractMaterialInfo targetMatInfo) + { + bool res = false; + + if(effectProperty.fullKeywordNames.Length == 1) + { + if (targetMatInfo.IsKeywordEnabled(effectProperty.fullKeywordNames[0])) + { + res = true; + selectedIndex = 0; + } + } + else + { + for(int i = 0; i < effectProperty.fullKeywordNames.Length; i++) + { + if (targetMatInfo.IsKeywordEnabled(effectProperty.fullKeywordNames[i])) + { + res = true; + selectedIndex = i; + break; + } + } + } + + return res; + } + + public static void ResetProperty(MaterialProperty targetProperty, AllIn13DShaderInspectorReferences references, AbstractMaterialInfo targetMatInfo) + { + Shader shader = targetMatInfo.mat.shader; + + if (references.materialWithDefaultValues == null) + { + references.materialWithDefaultValues = new Material(shader); + } + + AllIn1ShaderPropertyType targetPropertyType = EditorUtils.GetShaderTypeByMaterialProperty(targetProperty); + int propertyIndex = shader.FindPropertyIndex(targetProperty.name); + if (targetPropertyType == AllIn1ShaderPropertyType.Float || targetPropertyType == AllIn1ShaderPropertyType.Range) + { + targetProperty.floatValue = references.materialWithDefaultValues.GetFloat(targetProperty.name); + } + else if (targetPropertyType == AllIn1ShaderPropertyType.Vector) + { + targetProperty.vectorValue = references.materialWithDefaultValues.GetVector(targetProperty.name); + } + else if (targetPropertyType == AllIn1ShaderPropertyType.Color) + { + targetProperty.colorValue = references.materialWithDefaultValues.GetColor(targetProperty.name); + } + else if (targetPropertyType == AllIn1ShaderPropertyType.Texture) + { + targetProperty.textureValue = references.materialWithDefaultValues.GetTexture(targetProperty.name); + } + } + + public static void EnableEffect(AllIn13DEffectConfig effectConfig, AllIn13DShaderInspectorReferences references, AbstractMaterialInfo targetMatInfo) + { + for (int i = 0; i < effectConfig.keywords.Count; i++) + { + string kw = effectConfig.keywords[i].keyword; + targetMatInfo.EnableKeyword(kw); + } + } + + public static void EnableEffectToggle(AllIn13DEffectConfig effectConfig, AllIn13DShaderInspectorReferences references, AbstractMaterialInfo targetMatInfo) + { + targetMatInfo.EnableKeyword(effectConfig.keywords[0].keyword); + references.matProperties[effectConfig.keywordPropertyIndex].floatValue = 1f; + } + + public static void DisableEffectToggle(AllIn13DEffectConfig effectConfig, AllIn13DShaderInspectorReferences references, AbstractMaterialInfo targetMatInfo) + { + targetMatInfo.DisableKeyword(effectConfig.keywords[0].keyword); + references.matProperties[effectConfig.keywordPropertyIndex].floatValue = 0f; + } + + public static void EnableEffectByIndex(AllIn13DEffectConfig effectConfig, int index, AllIn13DShaderInspectorReferences references, AbstractMaterialInfo targetMatInfo) + { + DisableEffect(effectConfig, targetMatInfo); + string kwToEnable = effectConfig.keywords[index].keyword; + + targetMatInfo.EnableKeyword(kwToEnable); + } + + public static void DisableEffect(AllIn13DEffectConfig effectConfig, AllIn13DShaderInspectorReferences references) + { + for(int i = 0; i < references.targetMatInfos.Length; i++) + { + DisableEffect(effectConfig, references.targetMatInfos[i]); + } + } + + public static void DisableEffect(AllIn13DEffectConfig effectConfig, AbstractMaterialInfo targetMatInfo) + { + for (int i = 0; i < effectConfig.keywords.Count; i++) + { + string kw = effectConfig.keywords[i].keyword; + + targetMatInfo.DisableKeyword(kw); + } + } + + public static bool ContainsKeyword(Material mat, string kw, LocalKeyword[] enabledKeywords) + { + bool res = false; + for (int i = 0; i < enabledKeywords.Length; i++) + { + if (enabledKeywords[i].name == kw) + { + res = true; + break; + } + } + + return res; + } + + + + public int GetKeywordIndex(string keyword) + { + int res = -1; + for (int i = 0; i < keywords.Count; i++) + { + if (keywords[i].keyword == keyword) + { + res = i; + break; + } + } + + return res; + } + + public string[] GetPropertyNames() + { + string[] res = new string[effectProperties.Count]; + + for(int i = 0; i < effectProperties.Count; i++) + { + res[i] = $"{effectProperties[i].displayName} ({effectProperties[i].propertyName})"; + } + + return res; + } + + public bool ContainsKeywordProperties() + { + bool res = false; + + for(int i = 0; i < effectProperties.Count; i++) + { + if (effectProperties[i].IsPropertyWithKeywords()) + { + res = true; + break; + } + } + + return res; + } + + public GUIContent CreateGUIContent(int globalEffectIndex, int keywordSelectedIndex) + { + string label = $"{globalEffectIndex}. {displayName}"; + string tooltip = keywords[keywordSelectedIndex].keyword + " (C#)"; + + GUIContent res = new GUIContent(label, tooltip); + + return res; + } + + public bool ContainsKeyword(string keyword) + { + bool res = false; + + for(int i = 0; i < keywords.Count; i++) + { + if (keywords[i].keyword == keyword) + { + res = true; + break; + } + } + + return res; + } + + public bool ContainsSomeKeywordFromList(string[] keywords) + { + bool res = false; + + for(int i = 0; i < keywords.Length; i++) + { + if (ContainsKeyword(keywords[i])) + { + res = true; + break; + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/AllIn13DEffectConfig.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DEffectConfig.cs.meta new file mode 100644 index 0000000..d1a490a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DEffectConfig.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 9e56d697165908f4a802d77da51b7913 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/AllIn13DEffectConfig.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderAssemebly.Editor.asmdef b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderAssemebly.Editor.asmdef new file mode 100644 index 0000000..a2eac56 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderAssemebly.Editor.asmdef @@ -0,0 +1,21 @@ +{ + "name": "AllIn13DShaderAssemebly.Editor", + "rootNamespace": "", + "references": [ + "GUID:1b1237e1ff5eb504898a6f1f45e9b538", + "GUID:c579267770062bf448e75eb160330b7f", + "GUID:15fc0a57446b3144c949da3e2b9737a9", + "GUID:3eae0364be2026648bf74846acb8a731" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderAssemebly.Editor.asmdef.meta b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderAssemebly.Editor.asmdef.meta new file mode 100644 index 0000000..6e16e5a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderAssemebly.Editor.asmdef.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 9180457c15877e84e9afced3000f4ee1 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderAssemebly.Editor.asmdef + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderConfig.cs b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderConfig.cs new file mode 100644 index 0000000..aab00b0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderConfig.cs @@ -0,0 +1,19 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public static class AllIn13DShaderConfig + { + //Default Material Name + public const string MATERIAL_NAME_DEFAULT = "AllIn13DMaterial.mat"; + + public static Texture GetInspectorImage() + { + Texture res = null; + + res = EditorUtils.FindAsset("AllIn13dShaderCustomEditorHeader"); + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderConfig.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderConfig.cs.meta new file mode 100644 index 0000000..ae8fb91 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderConfig.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 7ac8fcdac0e79974c8d61e1de5dc57ed +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderConfig.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderInspectorReferences.cs b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderInspectorReferences.cs new file mode 100644 index 0000000..39eb4f8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderInspectorReferences.cs @@ -0,0 +1,194 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class AllIn13DShaderInspectorReferences + { + public MaterialProperty[] matProperties; + public string[] oldKeyWords; + + public AbstractMaterialInfo[] targetMatInfos; + + public Material materialWithDefaultValues; + + public MaterialEditor editorMat; + + //Styles + private const int bigFontSize = 16, smallFontSize = 11; + public GUIStyle propertiesStyle, bigLabelStyle, smallLabelStyle, toggleButtonStyle, tabButtonStyle; + + //Outline Effect + public AllIn13DEffectConfig outlineEffectConfig; + + //Cast Shadows Effect + public AllIn13DEffectConfig castShadowsEffectConfig; + + //Effects Profile Collection + public EffectsProfileCollection effectsProfileCollection; + + public AllIn13DShaderInspectorReferences() + { + propertiesStyle = new GUIStyle(EditorStyles.helpBox); + propertiesStyle.margin = new RectOffset(0, 0, 0, 0); + + bigLabelStyle = new GUIStyle(EditorStyles.boldLabel); + bigLabelStyle.fontSize = bigFontSize; + + smallLabelStyle = new GUIStyle(EditorStyles.boldLabel); + smallLabelStyle.fontSize = smallFontSize; + + toggleButtonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleCenter, richText = true }; + + tabButtonStyle = new GUIStyle(GUI.skin.button) { fontSize = 10 }; + } + + public void Setup(MaterialEditor materialEditor, MaterialProperty[] properties) + { + this.editorMat = materialEditor; + + if (this.targetMatInfos == null) + { + this.targetMatInfos = new AbstractMaterialInfo[materialEditor.targets.Length]; + for (int i = 0; i < materialEditor.targets.Length; i++) + { + Material mat = (Material)materialEditor.targets[i]; + targetMatInfos[i] = AbstractMaterialInfo.CreateInstance(mat); + } + + materialWithDefaultValues = new Material(targetMatInfos[0].mat.shader); + } + + this.effectsProfileCollection = GlobalConfiguration.instance.effectsProfileCollection; + + this.matProperties = properties; + } + + public void SetOutlineEffect(PropertiesConfig propertiesConfig) + { + this.outlineEffectConfig = propertiesConfig.FindEffectConfigByID("OUTLINETYPE"); + } + + public void SetCastShadowsEffect(PropertiesConfig propertiesConfig) + { + this.castShadowsEffectConfig = propertiesConfig.FindEffectConfigByID("CAST_SHADOWS_ON"); + } + + public void SetMaterialsDirty() + { + for(int i = 0; i < targetMatInfos.Length; i++) + { + EditorUtility.SetDirty(targetMatInfos[i].mat); + } + } + + public Shader GetShader() + { + return targetMatInfos[0].mat.shader; + } + + public bool IsKeywordEnabled(string keyword) + { + bool res = true; + + for(int i = 0; i < targetMatInfos.Length; i++) + { + res = res && targetMatInfos[i].IsKeywordEnabled(keyword); + } + + return res; + } + + public void RefreshMaterialKeywords() + { + for(int i = 0; i < this.targetMatInfos.Length; i++) + { + this.targetMatInfos[i].RefreshKeywords(); + } + } + + public bool IsShaderVariant() + { + bool res = true; + + for(int i = 0; i < targetMatInfos.Length; i++) + { + res = res && targetMatInfos[i].IsShaderVariant(); + } + + return res; + } + + public bool IsEffectEnabled(AllIn13DEffectConfig effectConfig, ref int selectedIndex) + { + bool res = true; + + for (int i = 0; i < targetMatInfos.Length; i++) + { + int enumIdx = -1; + AbstractMaterialInfo matInfo = targetMatInfos[i]; + + bool effectEnabled = AllIn13DEffectConfig.IsEffectEnabled(effectConfig, ref enumIdx, matInfo); + + if (i == 0) + { + selectedIndex = enumIdx; + } + else + { + res = res && (enumIdx == selectedIndex); + } + } + + return res; + } + + public bool IsEffectPropertyEnabled(EffectProperty effectProperty, ref int selectedIndex) + { + bool res = true; + + for (int i = 0; i < targetMatInfos.Length; i++) + { + int enumIdx = 0; + AbstractMaterialInfo matInfo = targetMatInfos[i]; + + res = res && AllIn13DEffectConfig.IsEffectPropertyEnabled(effectProperty, ref enumIdx, matInfo); + + if (i == 0) + { + selectedIndex = enumIdx; + } + else + { + res = res && (enumIdx == selectedIndex); + } + } + + return res; + } + + public bool AreAllMaterialsShaderVariant() + { + bool res = true; + + for(int i = 0; i < targetMatInfos.Length; i++) + { + res = res && targetMatInfos[i].IsShaderVariant(); + } + + return res; + } + + public bool AreAllMaterialsShaderGeneric() + { + bool res = true; + + for (int i = 0; i < targetMatInfos.Length; i++) + { + res = res && !targetMatInfos[i].IsShaderVariant(); + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderInspectorReferences.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderInspectorReferences.cs.meta new file mode 100644 index 0000000..57967f0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderInspectorReferences.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 42ff15ffadcc8ae42982fa48192469ea +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/AllIn13DShaderInspectorReferences.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/CommonMaterialInfo.cs b/Assets/Plugins/AllIn13DShader/Editor/CommonMaterialInfo.cs new file mode 100644 index 0000000..692b69a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CommonMaterialInfo.cs @@ -0,0 +1,42 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class CommonMaterialInfo : AbstractMaterialInfo + { + public CommonMaterialInfo(Material mat) : base(mat) + { + RefreshKeywords(); + } + + public EffectsProfile effectProfile; + + public override void RefreshKeywords() + { + this.enabledKeywords = new string[mat.enabledKeywords.Length]; + for (int i = 0; i < enabledKeywords.Length; i++) + { + this.enabledKeywords[i] = mat.enabledKeywords[i].name; + } + } + + public override void EnableKeyword(string keyword) + { + mat.EnableKeyword(keyword); + + RefreshKeywords(); + } + + public override void DisableKeyword(string keyword) + { + mat.DisableKeyword(keyword); + + RefreshKeywords(); + } + + public override bool IsShaderVariant() + { + return false; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/CommonMaterialInfo.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/CommonMaterialInfo.cs.meta new file mode 100644 index 0000000..69aca93 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CommonMaterialInfo.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 81dd06e6f7828b340ab17dfd17529a9b +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/CommonMaterialInfo.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/CommonMessages.cs b/Assets/Plugins/AllIn13DShader/Editor/CommonMessages.cs new file mode 100644 index 0000000..725ef1d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CommonMessages.cs @@ -0,0 +1,8 @@ +namespace AllIn13DShader +{ + public static class CommonMessages + { + public const string URP_PIPELINE_NOT_ASSIGNED = "URP installed, but Render Pipeline Asset not assigned\nPlease assign a URP Render Pipeline Asset \nOr remove URP in the Package Manager"; + public const string URP_PIPELINE_NOT_ASSIGNED_DOC_LINK = "https://seasidestudios.gitbook.io/seaside-studios/3d-shader/urp-and-post-processing-setup"; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/CommonMessages.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/CommonMessages.cs.meta new file mode 100644 index 0000000..52dbc19 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CommonMessages.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: dc117341064526c43aa23854ad769ab9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/CommonMessages.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Constants.cs b/Assets/Plugins/AllIn13DShader/Editor/Constants.cs new file mode 100644 index 0000000..378fdd3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Constants.cs @@ -0,0 +1,130 @@ +using System.IO; + +namespace AllIn13DShader +{ + public static class Constants + { + public static string VERSION = "2.72"; + + public const string EFFECT_ATTRIBUTE_PREFIX = "Effect("; + public const string EFFECT_PROPERTY_ATTRIBUTE_PREFIX = "EffectProperty("; + //public const string HEADER_PREFIX = "Header("; + public const string SINGLE_PROPERTY_ATTRIBUTE = "SingleProperty"; + public const string ADVANCED_PROPERTY_ATTRIBUTE = "AdvancedProperty"; + + + public const string SHADER_ROOT = "AllIn13DShader"; + + public static string[] SHADERS_NAMES = new string[] + { + "AllIn13DShader", + "AllIn13DShader_NoShadowCaster", + "AllIn13DShaderOutline_NoShadowCaster", + "AllIn13DShaderOutline", + }; + + public static string MAIN_SHADER_NAME + { + get + { + return SHADERS_NAMES[0]; + } + } + + public static string SHADER_FULL_NAME_ALLIN13D + { + get + { + return SHADER_ROOT + "/" + MAIN_SHADER_NAME; + } + } + + public static string SHADER_FULL_NAME_ALLIN13D_OUTLINE + { + get + { + return SHADER_ROOT + "/" + SHADERS_NAMES[3]; + } + } + + public static string SHADER_NAME_ALLIN13D_OUTLINE = "AllIn13DShaderOutline"; + + + + //=========== Paths =========== + public static string SHADERS_FOLDER_PATH = Path.Combine(GlobalConfiguration.instance.RootPluginPath, "Shaders");/*"Assets/AllIn13DShader/Shaders";*/ + public static string SHADERS_GENERIC_FOLDER_PATH = Path.Combine(SHADERS_FOLDER_PATH, "Generic Shaders"); + public static string SHADER_LIBRARY_FOLDER_PATH = Path.Combine(SHADERS_FOLDER_PATH, "ShaderLibrary"); + //public static string SHADERS_PROPERTIES_FOLDER_PATH = /*"Assets/AllIn13DShader/Editor"*/Path.Combine(GlobalConfiguration.instance.RootPluginPath, "Editor"); + public static string TEMPLATES_FOLDER = Path.Combine(GlobalConfiguration.instance.RootPluginPath, "Editor/Templates"); + public const string STANDARD_EXAMPLES_MATERIALS_LOCAL_PATH = "Demo/Materials/StandardExamples"; + public static string DEMO_SHADERS_BAKED_FOLDER_PATH = Path.Combine(GlobalConfiguration.instance.RootPluginPath, "Demo/Baked Shaders Demo/Shaders"); + + /* Shader Passes Paths */ + public const string MAIN_PASS_PATH = "Shaders/ShaderLibrary/AllIn13DShader_BasePass.hlsl"; + public const string LIGHT_ADD_PASS_PATH = "Shaders/ShaderLibrary/AllIn13DShaderLightAddPass.hlsl"; + public const string SHADOW_CASTER_PASS_PATH = "Shaders/ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl"; + public const string DEPTH_ONLY_PASS_PATH = "Shaders/ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl"; + public const string DEPTH_NORMALS_PASS_PATH = "Shaders/ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl"; + public const string META_PASS_PATH = "Shaders/ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl"; + public const string OUTLINE_PASS_PATH = "Shaders/ShaderLibrary/AllIn13DShader_OutlinePass.hlsl"; + + public const string BIRP_HELPER_PATH = "Shaders/ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl"; + public const string URP_HELPER_PATH = "Shaders/ShaderLibrary/AllIn13DShaderHelper_URP.hlsl"; + + //==================================== + + public const string KEYWORD_NONE = "NONE"; + + //Special Properties + public const string MATPROPERTY_RENDERING_MODE = "_RenderPreset"; + public const string MATPROPERTY_BLEND_SRC = "_BlendSrc"; + public const string MATPROPERTY_BLEND_DST = "_BlendDst"; + public const string KEYWORD_ALLIN13D_SURFACE_TRANSPARENT = "_ALLIN13D_SURFACE_TRANSPARENT"; + + //Drawers IDs + public const string GENERAL_EFFECT_DRAWER_ID = "GENERAL_EFFECT_DRAWER"; + public const string TRIPLANAR_EFFECT_DRAWER_ID = "TRIPLANAR_EFFECT_DRAWER"; + public const string COLOR_RAMP_EFFECT_DRAWER_ID = "COLOR_RAMP_EFFECT_DRAWER"; + public const string OUTLINE_DRAWER_ID = "OUTLINE_DRAWER_ID"; + public const string TEXTURE_BLENDING_EFFECT_DRAWER_ID = "TEXTURE_BLENDING_EFFECT_DRAWER"; + public const string NORMAL_MAP_EFFECT_DRAWER_ID = "NORMAL_MAP_EFFECT_DRAWER"; + + //Regex + public const string REGEX_EFFECT = @"\(EffectID#([\w\s]+),.*GroupID#([\w\s]+)(?:,.*AllowReset#([\w\s]+))?(?:,.*DependentOn#([\w\s]+))?(?:,.*IncompatibleWith#([\w\s]+))?(?:,.*Doc#([\w\s\\\.]+))?(?:,.*CustomDrawer#([\w\s]+))?(?:,.*ExtraPasses#[\s]*\(([\w\s,]+)\))?\)"; + public const string REGEX_EFFECT_PROPERTY = @"EffectProperty\((.*)\)"; + //public const string REGEX_EFFECT_PROOPERTY_COMPLETE = @"EffectProperty\(ParentEffect# ([\w\s]+), Keywords\((.*)\)\)"; + public const string REGEX_EFFECT_PROOPERTY_COMPLETE = @"EffectProperty\(ParentEffect# ([\w\s]+)(?:,.*KeywordsOp# ([\w]+))?(?:,.*IncompatibleWithKws\(([\w]+)\))?, Keywords\((.*)\), AllowReset# ([\w]+)\)"; + public const string REGEX_PARENT_EFFECT_KEYWORDS = @".*\((.*)\)"; + public const string REGEX_KEYWORDS_ENUM = @"KeywordEnum\((.*)\)"; + public const string REGEX_TOGGLE = @"Toggle\((.*)\)"; + + //Editor Prefs Keys + public const string LAST_TIME_SHADER_PROPERTIES_REBUILT_KEY = "AllIn13DShader_RebuiltTime"; + public const string LAST_RENDER_PIPELINE_CHECKED_KEY = "AllIn13DShader_LastRenderPipeline"; + + //Strings + public const string HDR_STR = "HDR"; + public const string KEYWORD_ENUM_STR = "KeywordEnum"; + public const string ON_STR = "On"; + public const string OFF_STR = "Off"; + public const string DISABLED_ENUM_OPTION_STR = "None"; + + //Default Names + public const string DEFAULT_NAME_EFFECTS_PROFILE = "EffectsProfile"; + + // + public const string INCLUDE_LINE_FORMAT = @"#include ""{0}"""; + public const string DEFINE_LINE_FORMAT = @"#define {0}"; + + //Effect IDs + public const string EFFECT_ID_TRIPLANAR_MAPPING = "TRIPLANAR_MAPPING"; + public const string EFFECT_ID_EMISSION = "EMISSION"; + + //Effect Group IDs + public const string EFFECT_GROUP_ID_UV_EFFECTS = "UVEffects"; + + //Main Assembly Name + public const string MAIN_ASSEMBLY_NAME = "AllIn13DShaderAssembly.asmdef"; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Constants.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Constants.cs.meta new file mode 100644 index 0000000..7efc5b0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Constants.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 233adf119f33cfb40b410b4336a90123 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Constants.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors.meta b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors.meta new file mode 100644 index 0000000..4246fe1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 63d2b9e0902c63442b73dc870028b96a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderComponentCustomEditor.cs b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderComponentCustomEditor.cs new file mode 100644 index 0000000..3d4f19a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderComponentCustomEditor.cs @@ -0,0 +1,366 @@ +using System; +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; + +namespace AllIn13DShader +{ + [CustomEditor(typeof(AllIn13DShaderComponent))] + [CanEditMultipleObjects] + public class AllIn13DShaderComponentCustomEditor : Editor + { + private PropertiesConfigCollection propertiesConfigCollection; + private GlobalConfiguration globalConfiguration; + private Texture imageInspector; + + private void RefreshReferences() + { + propertiesConfigCollection = EditorUtils.FindAsset("PropertiesConfigCollection") as PropertiesConfigCollection; + if(propertiesConfigCollection == null) + { + propertiesConfigCollection = PropertiesConfigCreator.CreateConfig(); + } + + globalConfiguration = EditorUtils.FindAssetByName("GlobalConfiguration"); + } + + private void OnEnable() + { + if (!Application.isPlaying) + { + RefreshReferences(); + + bool isValidComponents = CheckSelectedComponents(); + if (!isValidComponents) + { + EditorUtility.DisplayDialog("Missing Renderer", "Some of the selected game objects have no Renderer component. AllIn13DShaderComponent will be removed", "Ok"); + return; + } + + CheckMaterialReference(); + } + } + + public override void OnInspectorGUI() + { + bool saveAssets = false; + + serializedObject.Update(); + + DrawHeaderImage(); + + EditorGUI.BeginDisabledGroup(Application.isPlaying); + if(GUILayout.Button("Deactivate All Effects")) + { + ExecuteActionAfterCheck(DeactivateAllEffects); + saveAssets = true; + } + + if (GUILayout.Button("New Clean Material")) + { + ExecuteActionAfterCheck(NewCleanMaterial); + } + + if(GUILayout.Button("Create New Material With Same Properties (SEE DOC)")) + { + ExecuteActionAfterCheck(MakeCopyMaterial); + } + + if(GUILayout.Button("Save Material To Folder (SEE DOC)")) + { + ExecuteActionAfterCheck(SaveMaterialToFolder); + } + + if(GUILayout.Button("Apply Material To All Children")) + { + ExecuteActionAfterCheck(ApplyMaterialToAllChildren); + } + + if (GUILayout.Button("Render Material To Image")) + { + ExecuteActionAfterCheck(RenderMaterialToImage); + } + EditorGUI.EndDisabledGroup(); + + serializedObject.ApplyModifiedProperties(); + + + if (saveAssets) + { + AssetDatabase.SaveAssets(); + EditorSceneManager.SaveOpenScenes(); + AssetDatabase.Refresh(); + } + + EditorGUILayout.Space(); + EditorUtils.DrawThinLine(); + + if (GUILayout.Button("Remove Component")) + { + RemoveComponent(); + } + + if(GUILayout.Button("Remove Component and Material")) + { + RemoveComponentAndMaterial(); + } + } + + private void DrawHeaderImage() + { + if(imageInspector == null) imageInspector = AllIn13DShaderConfig.GetInspectorImage(); + Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(32)); + GUI.DrawTexture(rect, imageInspector, ScaleMode.ScaleToFit, true); + } + + private void CheckMaterialReference() + { + for (int i = 0; i < targets.Length; i++) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + + Material currMaterial = allIn13DShaderComponent.currMaterial; + if (currMaterial == null || !propertiesConfigCollection.IsAllIn3DShaderMaterial(currMaterial)) + { + Shader shader = GlobalConfiguration.instance.shStandard; + //Shader shader = propertiesConfigCollection.shaderPropertiesConfig[0].shader; + + Material oldMaterial = allIn13DShaderComponent.currMaterial; + allIn13DShaderComponent.NewCleanMaterial(shader, globalConfiguration.defaultPreset); + + MaterialConverterTool.ApplyConversion(oldMaterial, allIn13DShaderComponent.currMaterial); + } + } + + EditorUtils.SetDirtyCurrentScene(); + } + + private void DeactivateAllEffects() + { + bool successOperation = true; + bool selectedComponentsAreValid = CheckSelectedComponents(); + + for (int i = 0; i < targets.Length; i++) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + successOperation = successOperation && allIn13DShaderComponent.CheckValidComponent(); + + Material mat = allIn13DShaderComponent.currMaterial; + PropertiesConfig propertiesConfig = propertiesConfigCollection.FindPropertiesConfigByShader(mat.shader); + + List effects = propertiesConfig.GetAllEffects(); + + for (int j = 0; j < effects.Count; j++) + { + mat.SetFloat(effects[j].keywordPropertyName, 0f); + } + + EditorUtility.SetDirty(allIn13DShaderComponent); + EditorUtility.SetDirty(mat); + } + } + + private void NewCleanMaterial() + { + for (int i = 0; i < targets.Length; i++) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + + Shader shader = GlobalConfiguration.instance.shStandard; + //Shader shader = propertiesConfigCollection.shaderPropertiesConfig[0].shader; + allIn13DShaderComponent.NewCleanMaterial(shader, globalConfiguration.defaultPreset); + } + } + + public void MakeCopyMaterial() + { + for (int i = 0; i < targets.Length; i++) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + + Renderer currRenderer = allIn13DShaderComponent.currRenderer; + Material currMat = currRenderer.sharedMaterial; + + string materialName = "MAT_" + allIn13DShaderComponent.gameObject.name; + Material copy = new Material(currMat); + copy.name = materialName; + + currRenderer.sharedMaterial = copy; + + EditorUtility.SetDirty(allIn13DShaderComponent); + } + } + + public void SaveMaterialToFolder() + { + for (int i = 0; i < targets.Length; i++) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + SaveMaterialToFolder(allIn13DShaderComponent); + } + + EditorUtils.SetDirtyCurrentScene(); + } + + private bool CheckSelectedComponents() + { + bool res = true; + + for (int i = 0; i < targets.Length; i++) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + + bool isValid = allIn13DShaderComponent.CheckValidComponent(); + if (!isValid) + { + DestroyImmediate(allIn13DShaderComponent); + } + + res = res && isValid; + } + + return res; + } + + private void ExecuteActionAfterCheck(Action action) + { + bool selectedComponentsAreValid = CheckSelectedComponents(); + + if (selectedComponentsAreValid) + { + action(); + } + else + { + SceneView.lastActiveSceneView.ShowNotification(new GUIContent("Some of the selected components are not valid")); + } + } + + private void SaveMaterialToFolder(AllIn13DShaderComponent comp) + { + Material matToSave = comp.currMaterial; + bool isAlreadySaved = AssetDatabase.Contains(matToSave); + if (isAlreadySaved) + { + matToSave = comp.DuplicateCurrentMaterial(); + } + + string folderPath = GlobalConfiguration.instance.MaterialSavePath; + if (!Directory.Exists(folderPath)) + { + bool ok = EditorUtility.DisplayDialog("The desired save folder doesn't exist", + "Go to Window -> AllIn13DShaderWindow and set a valid folder", "Set default values and save material", "Cancel"); + + if (ok) + { + Directory.CreateDirectory(folderPath); + } + } + + if (Directory.Exists(folderPath)) + { + string fullPath = Path.Combine(folderPath, matToSave.name + ".mat"); + fullPath = AssetDatabase.GenerateUniqueAssetPath(fullPath); + + AssetDatabase.CreateAsset(matToSave, fullPath); + AssetDatabase.Refresh(); + + EditorGUIUtility.PingObject(matToSave); + } + } + + private void ApplyMaterialToAllChildren() + { + for (int i = 0; i < targets.Length; i++) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + allIn13DShaderComponent.ApplyMaterialToChildren(); + + EditorUtility.SetDirty(allIn13DShaderComponent); + } + + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + + private void RenderMaterialToImage() + { + for (int i = 0; i < targets.Length; i++) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + RenderToImage(allIn13DShaderComponent); + + EditorUtility.SetDirty(allIn13DShaderComponent); + } + } + + public void RenderToImage(AllIn13DShaderComponent allIn13DShaderComponent) + { + Texture tex = allIn13DShaderComponent.currMaterial.GetTexture("_MainTex"); + if (tex != null) + { + string folderPath = GlobalConfiguration.instance.RenderImageSavePath; + string fileName = allIn13DShaderComponent.gameObject.name + ".png"; + RenderMaterialToImageTool.RenderAndSaveTexture(allIn13DShaderComponent.currMaterial, tex, 4.0f, folderPath, fileName); + } + else + { + EditorUtility.DisplayDialog("No valid target texture found", + "All In 1 3DShader component couldn't find a valid Main Texture in this GameObject (" + + allIn13DShaderComponent.gameObject.name + + "). This means that the material you are using has no Main Texture or that the texture couldn't be reached through the Renderer component you are using." + + " Please make sure to have a valid Main Texture in the Material", "Ok"); + } + } + + private void RemoveComponent() + { + for (int i = targets.Length - 1; i >= 0; i--) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + DestroyImmediate(allIn13DShaderComponent); + } + + //EditorUtils.SetDirtyCurrentScene(); + + SetSceneDirty(); + EditorUtils.ShowNotification("AllIn3DShader: Component Removed"); + } + + private void RemoveComponentAndMaterial() + { + for (int i = 0; i < targets.Length; i++) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + allIn13DShaderComponent.CleanMaterial(); + } + + for (int i = targets.Length - 1; i >= 0; i--) + { + AllIn13DShaderComponent allIn13DShaderComponent = (AllIn13DShaderComponent)targets[i]; + DestroyImmediate(allIn13DShaderComponent); + } + + SetSceneDirty(); + } + + public void SetSceneDirty() + { + if (!Application.isPlaying) EditorSceneManager.MarkAllScenesDirty(); + + //If you get an error here please delete the code block below +#if UNITY_2021_2_OR_NEWER + var prefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); +#else + var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); +#endif + if (prefabStage != null) + { + EditorSceneManager.MarkSceneDirty(prefabStage.scene); + } + + //Until here + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderComponentCustomEditor.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderComponentCustomEditor.cs.meta new file mode 100644 index 0000000..75901f5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderComponentCustomEditor.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 445b6f2ff4b09ff4993b2516859d0467 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderComponentCustomEditor.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderMaterialInspector.cs b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderMaterialInspector.cs new file mode 100644 index 0000000..fd92e94 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderMaterialInspector.cs @@ -0,0 +1,416 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + [CanEditMultipleObjects] + public class AllIn13DShaderMaterialInspector : ShaderGUI + { + private PropertiesConfigCollection propertiesConfigCollection; + + private PropertiesConfig currentPropertiesConfig; + + private AllIn13DShaderInspectorReferences inspectorReferences; + private AbstractEffectDrawer[] drawers; + private GlobalPropertiesDrawer globalPropertiesDrawer; + private AdvancedPropertiesDrawer advancedPropertiesDrawer; + + private MaterialPresetCollection blendingModeCollection; + + private MaterialProperty matPropertyRenderPreset; + private MaterialProperty matPropertyBlendSrc; + private MaterialProperty matPropertyBlendDst; + private MaterialProperty matPropertyZWrite; + + private int lastRenderQueue; + + private static CommonStyles commonStyles; + + private void RefreshReferences(MaterialEditor materialEditor, MaterialProperty[] properties) + { + if (inspectorReferences == null) + { + inspectorReferences = new AllIn13DShaderInspectorReferences(); + inspectorReferences.Setup(materialEditor, properties); + + if (lastRenderQueue > 0) + { + for(int i = 0; i < inspectorReferences.targetMatInfos.Length; i++) + { + inspectorReferences.targetMatInfos[i].mat.renderQueue = lastRenderQueue; + } + } + } + + if (propertiesConfigCollection == null) + { + string[] guids = AssetDatabase.FindAssets("PropertiesConfigCollection t:PropertiesConfigCollection"); + if(guids.Length == 0) + { + Debug.LogWarning("PropertiesConfigCollection not found in the project. Configuring..."); + this.propertiesConfigCollection = PropertiesConfigCreator.CreateConfig(); + Debug.LogWarning("AllIn13DShader configured"); + } + else + { + string path = AssetDatabase.GUIDToAssetPath(guids[0]); + propertiesConfigCollection = AssetDatabase.LoadAssetAtPath(path); + } + + RefreshPropertiesConfig(); + } + + if (blendingModeCollection == null) + { + blendingModeCollection = (MaterialPresetCollection)EditorUtils.FindAsset("BlendingModeCollection"); + } + + CreateDrawers(); + + matPropertyRenderPreset = inspectorReferences.matProperties[currentPropertiesConfig.renderPreset]; + matPropertyBlendSrc = inspectorReferences.matProperties[currentPropertiesConfig.blendSrcIdx]; + matPropertyBlendDst = inspectorReferences.matProperties[currentPropertiesConfig.blendDstIdx]; + matPropertyZWrite = inspectorReferences.matProperties[currentPropertiesConfig.zWriteIndex]; + + //We ensure that data is refreshed. Sometimes objects are not null but we need to refresh the references + inspectorReferences.Setup(materialEditor, properties); + + if(commonStyles == null) + { + commonStyles = new CommonStyles(); + } + + RefreshDrawers(); + } + + private void ResetReferences() + { + this.propertiesConfigCollection = null; + this.currentPropertiesConfig = null; + + inspectorReferences = null; + drawers = null; + + globalPropertiesDrawer = null; + advancedPropertiesDrawer = null; + } + + private void CreateDrawers() + { + if (propertiesConfigCollection == null || + currentPropertiesConfig == null || + inspectorReferences == null || + drawers == null || + globalPropertiesDrawer == null || + advancedPropertiesDrawer == null) + { + drawers = new AbstractEffectDrawer[0]; + + GeneralEffectDrawer generalEffectDrawer = new GeneralEffectDrawer(inspectorReferences, currentPropertiesConfig); + + EffectProperty mainNormalMapProperty = currentPropertiesConfig.FindEffectProperty("NORMAL_MAP", "_NormalMap"); + + TriplanarEffectDrawer triplanarEffectDrawer = new TriplanarEffectDrawer(mainNormalMapProperty, inspectorReferences, currentPropertiesConfig); + ColorRampEffectDrawer colorRampEffectDrawer = new ColorRampEffectDrawer(inspectorReferences, currentPropertiesConfig); + OutlineEffectDrawer outlineEffectDrawer = new OutlineEffectDrawer(inspectorReferences, currentPropertiesConfig); + TextureBlendingEffectDrawer vertexColorEffectDrawer = new TextureBlendingEffectDrawer(mainNormalMapProperty, inspectorReferences, currentPropertiesConfig); + NormalMapEffectDrawer normalMapEffectDrawer = new NormalMapEffectDrawer(inspectorReferences, currentPropertiesConfig); + + drawers = new AbstractEffectDrawer[] + { + generalEffectDrawer, + triplanarEffectDrawer, + colorRampEffectDrawer, + outlineEffectDrawer, + vertexColorEffectDrawer, + normalMapEffectDrawer + }; + + advancedPropertiesDrawer = new AdvancedPropertiesDrawer(currentPropertiesConfig.advancedProperties, currentPropertiesConfig.blendSrcIdx, currentPropertiesConfig.blendDstIdx, inspectorReferences); + } + + if (globalPropertiesDrawer == null) + { + globalPropertiesDrawer = new GlobalPropertiesDrawer(); + } + } + + private void RefreshDrawers() + { + for(int i = 0; i < drawers.Length; i++) + { + drawers[i].Refresh(inspectorReferences); + } + } + + private AbstractEffectDrawer FindEffectDrawerByID(string drawerID) + { + AbstractEffectDrawer res = null; + + for (int i = 0; i < drawers.Length; i++) + { + if (drawers[i].ID == drawerID) + { + res = drawers[i]; + break; + } + } + + return res; + } + + public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) + { + base.AssignNewShaderToMaterial(material, oldShader, newShader); + } + + private void RefreshPropertiesConfig() + { + Shader shader = inspectorReferences.GetShader(); + currentPropertiesConfig = propertiesConfigCollection.FindPropertiesConfigByShader(shader); + + inspectorReferences.SetOutlineEffect(currentPropertiesConfig); + inspectorReferences.SetCastShadowsEffect(currentPropertiesConfig); + } + + public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) + { + if (inspectorReferences != null && drawers != null) + { + inspectorReferences.Setup(materialEditor, properties); + } + + RefreshReferences(materialEditor, properties); + + commonStyles.InitStyles(); + +#if ALLIN13DSHADER_URP + bool urpCorrectlyConfigured = URPConfigurator.IsURPCorrectlyConfigured(); + if (!urpCorrectlyConfigured) + { + EditorGUILayout.LabelField(CommonMessages.URP_PIPELINE_NOT_ASSIGNED, commonStyles.warningLabel); + EditorUtils.DrawButtonLink(CommonMessages.URP_PIPELINE_NOT_ASSIGNED_DOC_LINK); + + GUILayout.Space(50f); + } + + EditorGUI.BeginDisabledGroup(!urpCorrectlyConfigured); +#endif + + DrawPresetsTabs(); + DrawAdvancedProperties(); + DrawGlobalProperties(); + DrawEffects(); + +#if ALLIN13DSHADER_URP + EditorGUI.EndDisabledGroup(); +#endif + + CheckLightmapFlags(); + bool shaderChanged = false; + for (int i = 0; i < inspectorReferences.targetMatInfos.Length; i++) + { + Material targetMat = inspectorReferences.targetMatInfos[i].mat; + + lastRenderQueue = targetMat.renderQueue; + + if (!inspectorReferences.targetMatInfos[i].IsShaderVariant()) + { + shaderChanged = shaderChanged || MaterialUtils.CheckMaterialShader(targetMat); + } + } + + + + EditorGUILayout.Separator(); + EditorUtils.DrawLine(Color.grey, 1, 3); + + if (inspectorReferences.AreAllMaterialsShaderGeneric()) + { + if (GUILayout.Button("Bake Shader Keywords")) + { + for (int i = 0; i < inspectorReferences.targetMatInfos.Length; i++) + { + string variantName = Selection.objects[i].name; + Shader newShader = ShaderVariantCreator.CreateVariantByMaterialInfo(currentPropertiesConfig, inspectorReferences.targetMatInfos[i], variantName); + inspectorReferences.targetMatInfos[i].mat.shader = newShader; + } + //Shader newShader = ShaderVariantCreator.CreateVariantByMaterialInfo(currentPropertiesConfig, inspectorReferences.targetMatInfos[0], variantName); + //materialEditor.SetShader(newShader); + + shaderChanged = true; + } + } + else + { + if (GUILayout.Button("Revert To Generic Shader")) + { + Shader currentShader = inspectorReferences.GetShader(); + GlobalConfiguration.instance.effectsProfileCollection.RemoveEffectsProfileByShader(currentShader); + + Shader newShader = Shader.Find(Constants.SHADER_FULL_NAME_ALLIN13D); + materialEditor.SetShader(newShader); + + shaderChanged = true; + } + } + + if (shaderChanged) + { + ResetReferences(); + } + } + + //private void CheckPasses(Material targetMat) + //{ + // if (targetMat.IsKeywordEnabled("_LIGHTMODEL_FASTLIGHTING") || targetMat.IsKeywordEnabled("_LIGHTMODEL_NONE")) + // { + // targetMat.SetShaderPassEnabled("ForwardAdd", false); + // } + // else + // { + // targetMat.SetShaderPassEnabled("ForwardAdd", true); + // } + //} + + private void DrawPresetsTabs() + { + EditorGUI.BeginChangeCheck(); + + string[] texts = blendingModeCollection.CreateStringsArray(); + + + int presetIndex = (int)matPropertyRenderPreset.floatValue; + if (presetIndex >= blendingModeCollection.presets.Length) + { + presetIndex = 1; + matPropertyRenderPreset.floatValue = presetIndex; + } + + BlendingMode previousPreset = blendingModeCollection[presetIndex]; + if(previousPreset == null) + { + previousPreset = blendingModeCollection[0]; + } + + int newIndex = (int)matPropertyRenderPreset.floatValue; + newIndex = GUILayout.SelectionGrid(newIndex, texts, 3, inspectorReferences.tabButtonStyle); + matPropertyRenderPreset.floatValue = newIndex; + if (EditorGUI.EndChangeCheck()) + { + BlendingMode selectedPreset = blendingModeCollection[newIndex]; + for(int i = 0; i < inspectorReferences.targetMatInfos.Length; i++) + { + Material targetMat = inspectorReferences.targetMatInfos[i].mat; + ApplyMaterialPreset(targetMat, previousPreset, selectedPreset); + } + } + } + + private void DrawAdvancedProperties() + { + //Security check + if (advancedPropertiesDrawer != null) + { + advancedPropertiesDrawer.Draw(); + } + } + + private void DrawGlobalProperties() + { + globalPropertiesDrawer.Draw(currentPropertiesConfig.singleProperties, inspectorReferences); + } + + private void DrawEffects() + { + int globalEffectIndex = 0; + for (int groupIdx = 0; groupIdx < currentPropertiesConfig.effectsGroups.Length; groupIdx++) + { + EffectGroup effectGroup = currentPropertiesConfig.effectsGroups[groupIdx]; + if (effectGroup.effects.Length <= 0) { continue; } + + EditorGUILayout.Separator(); + EditorUtils.DrawLine(Color.grey, 1, 3); + GUILayout.Label(effectGroup.DisplayName, inspectorReferences.bigLabelStyle); + + for (int effectIdx = 0; effectIdx < effectGroup.effects.Length; effectIdx++) + { + AllIn13DEffectConfig effectConfig = effectGroup.effects[effectIdx]; + + globalEffectIndex++; + + AbstractEffectDrawer drawer = FindEffectDrawerByID(effectConfig.effectDrawerID); + drawer.Draw(currentPropertiesConfig, effectConfig, globalEffectIndex); + } + } + } + + private void CheckLightmapFlags() + { + for (int i = 0; i < inspectorReferences.targetMatInfos.Length; i++) + { + AbstractMaterialInfo matInfo = inspectorReferences.targetMatInfos[i]; + AllIn13DEffectConfig emissionEffectConfig = propertiesConfigCollection.propertiesConfig.FindEffectConfigByID(Constants.EFFECT_ID_EMISSION); + bool emissionEnabled = AllIn13DEffectConfig.IsEffectEnabled(emissionEffectConfig, matInfo); + if (emissionEnabled) + { + matInfo.mat.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive; + } + else + { + matInfo.mat.globalIlluminationFlags = MaterialGlobalIlluminationFlags.EmissiveIsBlack; + } + } + } + + private void ApplyMaterialPreset(Material targetMat, BlendingMode previousPresset, BlendingMode newPreset) + { + matPropertyBlendSrc.floatValue = (float)newPreset.blendSrc; + matPropertyBlendDst.floatValue = (float)newPreset.blendDst; + matPropertyZWrite.floatValue = newPreset.depthWrite ? 1.0f : 0.0f; + + + lastRenderQueue = (int)newPreset.renderQueue; + targetMat.renderQueue = lastRenderQueue; + + if (previousPresset != newPreset && previousPresset.defaultEnabledEffects != null) + { + for (int i = 0; i < previousPresset.defaultEnabledEffects.Length; i++) + { + string effectID = previousPresset.defaultEnabledEffects[i]; + AllIn13DEffectConfig effectConfig = currentPropertiesConfig.FindEffectConfigByID(effectID); + + for(int matIdx = 0; matIdx < inspectorReferences.targetMatInfos.Length; matIdx++) + { + AbstractMaterialInfo matInfo = inspectorReferences.targetMatInfos[matIdx]; + AllIn13DEffectConfig.DisableEffectToggle(effectConfig, inspectorReferences, matInfo); + } + } + } + + if (newPreset.defaultEnabledEffects != null) + { + for (int matIdx = 0; matIdx < inspectorReferences.targetMatInfos.Length; matIdx++) + { + AbstractMaterialInfo matInfo = inspectorReferences.targetMatInfos[matIdx]; + + if (newPreset.isTransparent) + { + matInfo.EnableKeyword(Constants.KEYWORD_ALLIN13D_SURFACE_TRANSPARENT); + } + else + { + matInfo.DisableKeyword(Constants.KEYWORD_ALLIN13D_SURFACE_TRANSPARENT); + } + + for (int i = 0; i < newPreset.defaultEnabledEffects.Length; i++) + { + string effectID = newPreset.defaultEnabledEffects[i]; + AllIn13DEffectConfig effectConfig = currentPropertiesConfig.FindEffectConfigByID(effectID); + AllIn13DEffectConfig.EnableEffectToggle(effectConfig, inspectorReferences, matInfo); + } + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderMaterialInspector.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderMaterialInspector.cs.meta new file mode 100644 index 0000000..1e90d61 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderMaterialInspector.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 57331ffe54816494c92e6b25562e4ed5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn13DShaderMaterialInspector.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn1DepthColoringPropertiesCustomEditor.cs b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn1DepthColoringPropertiesCustomEditor.cs new file mode 100644 index 0000000..669b1b0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn1DepthColoringPropertiesCustomEditor.cs @@ -0,0 +1,29 @@ +using UnityEditor; + +namespace AllIn13DShader +{ + [CustomEditor(typeof(AllIn1DepthColoringProperties))] + public class AllIn1DepthColoringPropertiesCustomEditor : Editor + { + private AllIn1DepthColoringProperties depthColoringProperties; + + private DepthColoringPropertiesDrawer drawer; + + private void RefreshDrawer() + { + depthColoringProperties = (AllIn1DepthColoringProperties)target; + + if (drawer == null) + { + drawer = new DepthColoringPropertiesDrawer(depthColoringProperties); + } + } + + public override void OnInspectorGUI() + { + RefreshDrawer(); + + drawer.Draw(false); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn1DepthColoringPropertiesCustomEditor.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn1DepthColoringPropertiesCustomEditor.cs.meta new file mode 100644 index 0000000..9401808 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn1DepthColoringPropertiesCustomEditor.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 40a4840e946197045b8663f3d968727f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/AllIn1DepthColoringPropertiesCustomEditor.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/DepthColoringCameraCustomEditor.cs b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/DepthColoringCameraCustomEditor.cs new file mode 100644 index 0000000..6a3d1be --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/DepthColoringCameraCustomEditor.cs @@ -0,0 +1,71 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + [CustomEditor(typeof(DepthColoringCamera))] + public class DepthColoringCameraCustomEditor : Editor + { + private SerializedProperty spCam; + private SerializedProperty spDepthColoringProperties; + + private AllIn1DepthColoringProperties depthColoringProperties; + private DepthColoringPropertiesDrawer depthColoringPropertiesDrawer; + + private DepthColoringCamera depthColoringCamera; + + private bool depthColoringFoldout; + + private void RefreshReferences() + { + if(spCam == null) + { + spCam = serializedObject.FindProperty("cam"); + } + + if(spDepthColoringProperties == null) + { + spDepthColoringProperties = serializedObject.FindProperty("depthColoringProperties"); + } + } + + private void RefreshDepthColoringPropertiesDrawer() + { + if(depthColoringPropertiesDrawer == null && depthColoringProperties != null) + { + depthColoringPropertiesDrawer = new DepthColoringPropertiesDrawer(depthColoringProperties); + } + else if(depthColoringPropertiesDrawer != null && depthColoringProperties != null) + { + depthColoringPropertiesDrawer.SetDepthColoringProperties(depthColoringProperties); + } + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + RefreshReferences(); + + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(spCam); + EditorGUILayout.PropertyField(spDepthColoringProperties); + + serializedObject.ApplyModifiedProperties(); + + if(spDepthColoringProperties.objectReferenceValue != null) + { + GUILayout.Space(25f); + + depthColoringProperties = (AllIn1DepthColoringProperties)spDepthColoringProperties.objectReferenceValue; + + RefreshDepthColoringPropertiesDrawer(); + + if(depthColoringPropertiesDrawer != null) + { + depthColoringPropertiesDrawer.Draw(true); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/DepthColoringCameraCustomEditor.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/DepthColoringCameraCustomEditor.cs.meta new file mode 100644 index 0000000..6e9c7e1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/DepthColoringCameraCustomEditor.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 0f455792fcb55c34d97cd0b478de36ba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/DepthColoringCameraCustomEditor.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/EffectsProfileCollectionCustomEditor.cs b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/EffectsProfileCollectionCustomEditor.cs new file mode 100644 index 0000000..abeb4b3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/EffectsProfileCollectionCustomEditor.cs @@ -0,0 +1,13 @@ +using UnityEditor; + +namespace AllIn13DShader +{ + [CustomEditor(typeof(EffectsProfileCollection))] + public class EffectsProfileCollectionCustomEditor : Editor + { + public override void OnInspectorGUI() + { + + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/EffectsProfileCollectionCustomEditor.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/EffectsProfileCollectionCustomEditor.cs.meta new file mode 100644 index 0000000..6bce13e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/EffectsProfileCollectionCustomEditor.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: df521890445440245b75e88c4fb4bd73 +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/EffectsProfileCollectionCustomEditor.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/GlobalConfigurationCustomEditor.cs b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/GlobalConfigurationCustomEditor.cs new file mode 100644 index 0000000..484ff4e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/GlobalConfigurationCustomEditor.cs @@ -0,0 +1,13 @@ +using UnityEditor; + +namespace AllIn13DShader +{ + [CustomEditor(typeof(GlobalConfiguration))] + public class GlobalConfigurationCustomEditor : Editor + { + public override void OnInspectorGUI() + { + + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/GlobalConfigurationCustomEditor.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/GlobalConfigurationCustomEditor.cs.meta new file mode 100644 index 0000000..d390f29 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/GlobalConfigurationCustomEditor.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: c57330f81e2eed441862d8a92a0e63cf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/GlobalConfigurationCustomEditor.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/PropertiesConfigCollectionCustomEditor.cs b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/PropertiesConfigCollectionCustomEditor.cs new file mode 100644 index 0000000..e75a58c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/PropertiesConfigCollectionCustomEditor.cs @@ -0,0 +1,12 @@ +using UnityEditor; + +namespace AllIn13DShader +{ + [CustomEditor(typeof(PropertiesConfigCollection))] + public class PropertiesConfigCollectionCustomEditor : Editor + { + public override void OnInspectorGUI() + { + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/PropertiesConfigCollectionCustomEditor.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/PropertiesConfigCollectionCustomEditor.cs.meta new file mode 100644 index 0000000..8a04dd5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/PropertiesConfigCollectionCustomEditor.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 436434178bc9cbf449485b83a639cdbb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/PropertiesConfigCollectionCustomEditor.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/URPSettingsUserPrefCustomEditor.cs b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/URPSettingsUserPrefCustomEditor.cs new file mode 100644 index 0000000..c5a894d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/URPSettingsUserPrefCustomEditor.cs @@ -0,0 +1,14 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + [CustomEditor(typeof(URPSettingsUserPref))] + public class URPSettingsUserPrefCustomEditor : Editor + { + public override void OnInspectorGUI() + { + + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/URPSettingsUserPrefCustomEditor.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/URPSettingsUserPrefCustomEditor.cs.meta new file mode 100644 index 0000000..676ff5a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/CustomEditors/URPSettingsUserPrefCustomEditor.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 8ff9df7e6f241e844821ae6d61fb8b20 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/CustomEditors/URPSettingsUserPrefCustomEditor.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data.meta b/Assets/Plugins/AllIn13DShader/Editor/Data.meta new file mode 100644 index 0000000..9ab7cfc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fb3274d0917f10f4e932549862263caf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsExtraData.asset b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsExtraData.asset new file mode 100644 index 0000000..fb83a70 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsExtraData.asset @@ -0,0 +1,82 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 32438765f2955064bae29bed18ec5263, type: 3} + m_Name: EffectsExtraData + m_EditorClassIdentifier: + effectsExtraData: + - effectID: CUSTOM_SHADOW_COLOR + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/shadow-color + customMessages: + - message: "*You need to use ShadowsConfigurator.cs component\n in order to use + this effect." + keywords: [] + - effectID: DEPTH_COLORING + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/depth-coloring-stylized-fog + customMessages: + - message: "*You need to add DepthColoringCamera.cs component \nto the main camera + in order to use this effect." + keywords: [] + - effectID: LIGHTMODEL + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/fast-lighting + customMessages: + - message: "*You need to use FastLightConfigurator.cs component\n in order to + use this effect." + keywords: + - _LIGHTMODEL_FASTLIGHTING + - effectID: SHADINGMODEL + docURL: + customMessages: + - message: '*Usually looks best paired with a Specular Model' + keywords: + - _SHADINGMODEL_PBR + - effectID: RECALCULATE_NORMALS + docURL: + customMessages: + - message: '*Dynamically reconstructs surface normals from vertex positions, + ignoring mesh baked normals' + keywords: + - _SHADINGMODEL_PBR + - effectID: INTERSECTION_GLOW + docURL: + customMessages: + - message: '*You need to set the material to Transparent mode in order to use + this effect correctly' + keywords: [] + - effectID: INTERSECTION_FADE + docURL: + customMessages: + - message: '*You need to set the material to Transparent mode in order to use + this effect correctly' + keywords: [] + - effectID: OUTLINETYPE + docURL: + customMessages: + - message: '*If the material is transparent, you need to enable Depth Write. + Otherwise, the mesh will look completely black + +' + keywords: + - _OUTLINETYPE_SIMPLE + - _OUTLINETYPE_CONSTANT + - _OUTLINETYPE_FADEWITHDISTANCE + - effectID: WIND + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/wind-effect-and-wind-controller + customMessages: + - message: "*You need to use WindController.cs component\n in order to use this + effect." + keywords: [] + - effectID: RECEIVE_SHADOWS + docURL: https://seasidestudios.gitbook.io/seaside-studios/3d-shader/receive-shadows-and-stylized-shadows + customMessages: + - message: "*Additional lights will not be \naffected by this effect" + keywords: + - _RECEIVEDSHADOWSTYPE_STYLIZED diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsExtraData.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsExtraData.asset.meta new file mode 100644 index 0000000..bac915a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsExtraData.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: ab04b85ae78a31642964fa2facafc08b +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Data/EffectsExtraData.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups.meta b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups.meta new file mode 100644 index 0000000..917d805 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 20260d74bdf7b1543992369a55b37761 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroupGlobalConfigCollection.asset b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroupGlobalConfigCollection.asset new file mode 100644 index 0000000..672e375 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroupGlobalConfigCollection.asset @@ -0,0 +1,21 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5d4677818a6699f4c951378b8bbde688, type: 3} + m_Name: EffectGroupGlobalConfigCollection + m_EditorClassIdentifier: + effectGroupGlobalConfigs: + - {fileID: 11400000, guid: 05a6bce58cfc83a4293b054fcfc62a81, type: 2} + - {fileID: 11400000, guid: fcdc7c904b0215f4aabfa8ced0068841, type: 2} + - {fileID: 11400000, guid: d45649322d809684a8f280736df5ebc7, type: 2} + - {fileID: 11400000, guid: 987f969d8d3fec24bbb35df7779ba52b, type: 2} + - {fileID: 11400000, guid: 2f3fcb0996a83b64599ce17553aa6b13, type: 2} + - {fileID: 11400000, guid: d29aa9c55e3576d4bad55ec71545fe82, type: 2} diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroupGlobalConfigCollection.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroupGlobalConfigCollection.asset.meta new file mode 100644 index 0000000..e645f2e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroupGlobalConfigCollection.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 0906b01f0f78cfc4dad64f8257ffaf66 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroupGlobalConfigCollection.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_AlphaEffects.asset b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_AlphaEffects.asset new file mode 100644 index 0000000..3b32ffb --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_AlphaEffects.asset @@ -0,0 +1,17 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b755efcb87425049878cf9532c736c7, type: 3} + m_Name: EffectGroup_AlphaEffects + m_EditorClassIdentifier: + groupID: AlphaEffects + displayName: Alpha Effects + libraryFileName: AllIn13DShader_AlphaEffects diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_AlphaEffects.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_AlphaEffects.asset.meta new file mode 100644 index 0000000..a0efd61 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_AlphaEffects.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: d45649322d809684a8f280736df5ebc7 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_AlphaEffects.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_ColorEffects.asset b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_ColorEffects.asset new file mode 100644 index 0000000..21475a3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_ColorEffects.asset @@ -0,0 +1,17 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b755efcb87425049878cf9532c736c7, type: 3} + m_Name: EffectGroup_ColorEffects + m_EditorClassIdentifier: + groupID: ColorEffects + displayName: Color Effects + libraryFileName: AllIn13DShader_FragmentEffects diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_ColorEffects.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_ColorEffects.asset.meta new file mode 100644 index 0000000..a67e989 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_ColorEffects.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: fcdc7c904b0215f4aabfa8ced0068841 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_ColorEffects.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_Lighting.asset b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_Lighting.asset new file mode 100644 index 0000000..4659725 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_Lighting.asset @@ -0,0 +1,17 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b755efcb87425049878cf9532c736c7, type: 3} + m_Name: EffectGroup_Lighting + m_EditorClassIdentifier: + groupID: Lighting + displayName: Lighting + libraryFileName: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_Lighting.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_Lighting.asset.meta new file mode 100644 index 0000000..4ef3e36 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_Lighting.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 05a6bce58cfc83a4293b054fcfc62a81 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_Lighting.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_MeshEffects.asset b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_MeshEffects.asset new file mode 100644 index 0000000..2386bc1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_MeshEffects.asset @@ -0,0 +1,17 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b755efcb87425049878cf9532c736c7, type: 3} + m_Name: EffectGroup_MeshEffects + m_EditorClassIdentifier: + groupID: MeshEffects + displayName: Mesh Effects + libraryFileName: AllIn13DShader_VertexEffects diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_MeshEffects.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_MeshEffects.asset.meta new file mode 100644 index 0000000..be592ea --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_MeshEffects.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 987f969d8d3fec24bbb35df7779ba52b +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_MeshEffects.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_OtherEffects.asset b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_OtherEffects.asset new file mode 100644 index 0000000..dc248db --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_OtherEffects.asset @@ -0,0 +1,16 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b755efcb87425049878cf9532c736c7, type: 3} + m_Name: EffectGroup_OtherEffects + m_EditorClassIdentifier: + groupID: OtherEffects + displayName: Other Effects diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_OtherEffects.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_OtherEffects.asset.meta new file mode 100644 index 0000000..e0cdbb5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_OtherEffects.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: d29aa9c55e3576d4bad55ec71545fe82 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_OtherEffects.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_UVEffects.asset b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_UVEffects.asset new file mode 100644 index 0000000..5c1f6ea --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_UVEffects.asset @@ -0,0 +1,17 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b755efcb87425049878cf9532c736c7, type: 3} + m_Name: EffectGroup_UVEffects + m_EditorClassIdentifier: + groupID: UVEffects + displayName: UV Effects + libraryFileName: AllIn13DShader_UVEffects diff --git a/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_UVEffects.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_UVEffects.asset.meta new file mode 100644 index 0000000..07741e9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_UVEffects.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 2f3fcb0996a83b64599ce17553aa6b13 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Data/EffectsGroups/EffectGroup_UVEffects.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers.meta new file mode 100644 index 0000000..abd3f69 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8da84111dbb07224ab02fcbcd7ad8a4c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/AdvancedPropertiesDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/AdvancedPropertiesDrawer.cs new file mode 100644 index 0000000..052e76e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/AdvancedPropertiesDrawer.cs @@ -0,0 +1,102 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class AdvancedPropertiesDrawer + { + private List advancedPropertiesIndices; + private int blendSrcIndex; + private int blendDstIndex; + + private AllIn13DShaderInspectorReferences references; + + private MaterialProperty advancedPropertiesEnabledMatProperty; + + private bool AdvancedPropertiesEnabled + { + get + { + bool res = advancedPropertiesEnabledMatProperty.floatValue > 0; + return res; + } + set + { + float floatValue = value ? 1.0f : 0f; + advancedPropertiesEnabledMatProperty.floatValue = floatValue; + } + } + + public AdvancedPropertiesDrawer(List advancedPropertiesIndices, int blendSrcIndex, int blendDstIndex, AllIn13DShaderInspectorReferences references) + { + this.advancedPropertiesIndices = advancedPropertiesIndices; + this.blendSrcIndex = blendSrcIndex; + this.blendDstIndex = blendDstIndex; + + this.references = references; + + advancedPropertiesEnabledMatProperty = references.matProperties[advancedPropertiesIndices[0]]; + } + + public void Draw() + { + AdvancedPropertiesEnabled = GUILayout.Toggle(AdvancedPropertiesEnabled, new GUIContent("Show Advanced Configuration"), references.toggleButtonStyle); + if (AdvancedPropertiesEnabled) + { + EditorGUILayout.BeginVertical(references.propertiesStyle); + + MaterialProperty matPropertyBlendSrc = references.matProperties[blendSrcIndex]; + MaterialProperty matProeprtyBlendDst = references.matProperties[blendDstIndex]; + + EffectPropertyDrawer.DrawProperty( + materialProperty: matPropertyBlendSrc, + labelPrefix: string.Empty, + displayName: matPropertyBlendSrc.displayName, + customValue: string.Empty, + allowReset: false, + isKeywordProperty: false, + propertyType: EffectProperty.PropertyType.BASIC, + references); + + EffectPropertyDrawer.DrawProperty( + materialProperty: matProeprtyBlendDst, + labelPrefix: string.Empty, + displayName: matProeprtyBlendDst.displayName, + customValue: string.Empty, + allowReset: false, + isKeywordProperty: false, + propertyType: EffectProperty.PropertyType.BASIC, + references); + + EditorUtils.DrawThinLine(); + + for (int i = 1; i < advancedPropertiesIndices.Count; i++) + { + //if(i == blendSrcIndex || i == blendDstIndex) { continue; } + MaterialProperty matProperty = references.matProperties[advancedPropertiesIndices[i]]; + EffectPropertyDrawer.DrawProperty( + materialProperty: matProperty, + labelPrefix: string.Empty, + displayName: matProperty.displayName, + customValue: string.Empty, + allowReset: false, + isKeywordProperty: false, + propertyType: EffectProperty.PropertyType.BASIC, + references: references); + + EditorUtils.DrawThinLine(); + } + + references.editorMat.EnableInstancingField(); + + Rect rect = EditorGUILayout.GetControlRect(); + rect.x += 3f; + rect.width -= 3f; + references.editorMat.RenderQueueField(rect); + + EditorGUILayout.EndVertical(); + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/AdvancedPropertiesDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/AdvancedPropertiesDrawer.cs.meta new file mode 100644 index 0000000..f213ef5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/AdvancedPropertiesDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 4877ef4771a6497458bd45402be12188 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/AdvancedPropertiesDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/AtlasPackerDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/AtlasPackerDrawer.cs new file mode 100644 index 0000000..1de1d22 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/AtlasPackerDrawer.cs @@ -0,0 +1,130 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class AtlasPackerDrawer + { + private AtlasPackerTool atlasPackerTool; + + public AtlasPackerValues ToolValues => atlasPackerTool.values; + + private CommonStyles commonStyles; + private SerializedObject soAtlasPackerValues; + + public AtlasPackerDrawer(AtlasPackerTool atlasPackerTool, CommonStyles commonStyles) + { + this.atlasPackerTool = atlasPackerTool; + this.commonStyles = commonStyles; + + RefreshAtlasPackerValues(); + } + + private void RefreshAtlasPackerValues() + { + soAtlasPackerValues = new SerializedObject(ToolValues); + } + + public void Draw() + { + soAtlasPackerValues.Update(); + + if (ToolValues == null) + { + RefreshAtlasPackerValues(); + } + + GUILayout.Label("Texture Atlas / Spritesheet Packer", commonStyles.bigLabel); + GUILayout.Space(20); + GUILayout.Label("Add Textures to the Atlas array", EditorStyles.boldLabel); + + + SerializedProperty atlasProperty = soAtlasPackerValues.FindProperty("atlas"); + EditorGUILayout.PropertyField(atlasProperty, true, GUILayout.MaxWidth(200)); + soAtlasPackerValues.ApplyModifiedProperties(); + + //ToolValues.atlas = Atlas; + + ToolValues.squareAtlas = EditorGUILayout.Toggle("Square Atlas?", ToolValues.squareAtlas, GUILayout.MaxWidth(200)); + EditorGUILayout.BeginHorizontal(); + { + if (ToolValues.squareAtlas) + { + ToolValues.atlasXCount = EditorGUILayout.IntSlider("Column and Row Count", ToolValues.atlasXCount, 1, 8, GUILayout.MaxWidth(302)); + ToolValues.atlasYCount = ToolValues.atlasXCount; + } + else + { + ToolValues.atlasXCount = EditorGUILayout.IntSlider("Column Count", ToolValues.atlasXCount, 1, 8, GUILayout.MaxWidth(302)); + GUILayout.Space(10); + ToolValues.atlasYCount = EditorGUILayout.IntSlider("Row Count", ToolValues.atlasYCount, 1, 8, GUILayout.MaxWidth(302)); + } + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + if (ToolValues.squareAtlas) + { + GUILayout.Label("Atlas Size:", GUILayout.MaxWidth(100)); + ToolValues.atlasSizesX = (TextureSizes)EditorGUILayout.EnumPopup(ToolValues.atlasSizesX, GUILayout.MaxWidth(200)); + ToolValues.atlasSizesY = ToolValues.atlasSizesX; + } + else + { + GUILayout.Label("Atlas Size X:", GUILayout.MaxWidth(100)); + ToolValues.atlasSizesX = (TextureSizes)EditorGUILayout.EnumPopup(ToolValues.atlasSizesX, GUILayout.MaxWidth(200)); + GUILayout.Space(10); + GUILayout.Label("Atlas Size Y:", GUILayout.MaxWidth(100)); + ToolValues.atlasSizesY = (TextureSizes)EditorGUILayout.EnumPopup(ToolValues.atlasSizesY, GUILayout.MaxWidth(200)); + } + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Atlas Filtering: ", GUILayout.MaxWidth(100)); + ToolValues.atlasFiltering = (FilterMode)EditorGUILayout.EnumPopup(ToolValues.atlasFiltering, GUILayout.MaxWidth(200)); + } + EditorGUILayout.EndHorizontal(); + + int atlasElements = atlasPackerTool.GetAtlasElements(); + int atlasWidth = (int)ToolValues.atlasSizesX; + int atlasHeight = (int)ToolValues.atlasSizesY; + GUILayout.Label("Output will be a " + ToolValues.atlasXCount + " X " + ToolValues.atlasYCount + " atlas, " + atlasElements + " elements in total. In a " + + atlasWidth + "pixels X " + atlasHeight + "pixels texture", EditorStyles.boldLabel); + + int usedAtlasSlots = 0; + for (int i = 0; i < ToolValues.atlas.Length; i++) + { + if (ToolValues.atlas[i] != null) + { + usedAtlasSlots++; + } + } + if (usedAtlasSlots > atlasElements) + { + GUILayout.Label("*Please reduce the Atlas texture slots by " + Mathf.Abs(atlasElements - ToolValues.atlas.Length) + " (extra textures will be ignored)", EditorStyles.boldLabel); + } + + if (atlasElements > usedAtlasSlots) + { + GUILayout.Label("*" + (atlasElements - usedAtlasSlots) + " atlas slots unused or null (it will be filled with black)", EditorStyles.boldLabel); + } + + GUILayout.Space(20); + GUILayout.Label("Select the folder where new Atlases will be saved", EditorStyles.boldLabel); + GlobalConfiguration.instance.AtlasesSavePath = EditorUtils.DrawSelectorFolder(GlobalConfiguration.instance.AtlasesSavePath, /*AllIn13DShaderConfig.ATLASES_SAVE_PATH_DEFAULT,*/ "Atlas"); + + + if (Directory.Exists(GlobalConfiguration.instance.AtlasesSavePath)) + { + if (GUILayout.Button("Create And Save Atlas Texture", GUILayout.MaxWidth(CommonStyles.BUTTON_WIDTH))) + { + atlasPackerTool.CreateAtlas(); + EditorUtils.SaveTextureAsPNG(GlobalConfiguration.instance.AtlasesSavePath, "Atlas", "Texture Atlas", ToolValues.createdAtlas, ToolValues.atlasFiltering, TextureImporterType.Default, TextureWrapMode.Clamp); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/AtlasPackerDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/AtlasPackerDrawer.cs.meta new file mode 100644 index 0000000..95e7a63 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/AtlasPackerDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: dca812f5788e4cb49942f0cb9072a9d3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/AtlasPackerDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/CommonStyles.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/CommonStyles.cs new file mode 100644 index 0000000..ea197a1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/CommonStyles.cs @@ -0,0 +1,76 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class CommonStyles + { + public const int BUTTON_WIDTH = 600; + public const int BIG_FONT_SIZE = 16; + + public GUIStyle shaderPropertiesStyle; + public GUIStyle wordWrappedStyle; + public GUIStyle style; + public GUIStyle bigLabel; + public GUIStyle warningLabel; + public GUIStyle okLabel; + public GUIStyle linkStyle; + public GUIStyle boxStyle; + + public void InitStyles() + { + if(wordWrappedStyle == null) + { + wordWrappedStyle = new GUIStyle(EditorStyles.largeLabel); + wordWrappedStyle.wordWrap = true; + } + + if(style == null) + { + style = new GUIStyle(EditorStyles.helpBox); + style.margin = new RectOffset(0, 0, 0, 0); + } + + if(bigLabel == null) + { + bigLabel = new GUIStyle(EditorStyles.boldLabel); + bigLabel.fontSize = BIG_FONT_SIZE; + } + + if(okLabel == null) + { + okLabel = new GUIStyle(EditorStyles.label); + okLabel.fontSize = BIG_FONT_SIZE; + okLabel.normal.textColor = Color.green; + okLabel.wordWrap = true; + okLabel.richText = true; + } + + if(warningLabel == null) + { + warningLabel = new GUIStyle(EditorStyles.label); + warningLabel.fontSize = BIG_FONT_SIZE; + warningLabel.normal.textColor = Color.yellow; + warningLabel.wordWrap = true; + warningLabel.richText = true; + } + + if(linkStyle == null) + { + linkStyle = new GUIStyle(EditorStyles.linkLabel); + } + + if(boxStyle == null) + { + boxStyle = new GUIStyle(EditorStyles.helpBox); + boxStyle.margin = new RectOffset(0, 0, 0, 0); + } + + if(shaderPropertiesStyle == null) + { + shaderPropertiesStyle = new GUIStyle(EditorStyles.helpBox); + shaderPropertiesStyle.margin = new RectOffset(25, 0, 0, 0); + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/CommonStyles.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/CommonStyles.cs.meta new file mode 100644 index 0000000..752cdf7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/CommonStyles.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: aba3dca1c691c3b4891e7a7e67ad55dc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/CommonStyles.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/DepthColoringPropertiesDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/DepthColoringPropertiesDrawer.cs new file mode 100644 index 0000000..45f2561 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/DepthColoringPropertiesDrawer.cs @@ -0,0 +1,111 @@ + +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class DepthColoringPropertiesDrawer + { + private AllIn1DepthColoringProperties depthColoringProperties; + + private CommonStyles commonStyles; + + private GradientEditorDrawer gradientDrawer; + + private DepthColoringCamera depthColoringCamera; + private bool isActive; + + public DepthColoringPropertiesDrawer(AllIn1DepthColoringProperties depthColoringProperties) + { + SetDepthColoringProperties(depthColoringProperties); + } + + public void SetDepthColoringProperties(AllIn1DepthColoringProperties depthColoringProperties) + { + this.depthColoringProperties = depthColoringProperties; + } + + private void RefreshReferences() + { + if (gradientDrawer == null) + { + gradientDrawer = new GradientEditorDrawer(); + } + + if (commonStyles == null) + { + commonStyles = new CommonStyles(); + commonStyles.InitStyles(); + } + + if(depthColoringCamera == null) + { + depthColoringCamera = GameObject.FindFirstObjectByType(); + } + } + + public void Draw(bool useBoxStyle = false) + { + RefreshReferences(); + + if (useBoxStyle) + { + EditorGUILayout.BeginVertical(commonStyles.boxStyle); + } + else + { + EditorGUILayout.BeginVertical(); + } + + + EditorGUI.BeginChangeCheck(); + + Rect rect = EditorGUILayout.GetControlRect(true, gradientDrawer.GetPropertyHeight()); + + depthColoringProperties.depthColoringGradientTex = (Texture2D)gradientDrawer.Draw(rect, depthColoringProperties.depthColoringGradientTex); + depthColoringProperties.depthZoneLength = EditorGUILayout.FloatField("Depth Zone Length", depthColoringProperties.depthZoneLength); + depthColoringProperties.depthColoringMinDepth = EditorGUILayout.FloatField("Depth Min", depthColoringProperties.depthColoringMinDepth); + depthColoringProperties.fallOff = EditorGUILayout.Slider("Fall Off", depthColoringProperties.fallOff, 0.1f, 1.5f); + + GUILayout.Space(20f); + if (depthColoringCamera == null) + { + EditorGUILayout.LabelField("Depth coloring camera not found in the scene. You need to add DepthColoringCamera.cs component to the main camera in order to use this effect.", commonStyles.warningLabel); + isActive = false; + } + else + { + isActive = depthColoringCamera.depthColoringProperties == depthColoringProperties; + + if (isActive) + { + EditorGUILayout.LabelField("Active", commonStyles.okLabel); + } + else + { + EditorGUILayout.LabelField("This properties are not active", commonStyles.warningLabel); + if (GUILayout.Button("Active")) + { + depthColoringCamera.depthColoringProperties = depthColoringProperties; + isActive = true; + + EditorUtils.SetDirtyCurrentScene(); + } + } + } + EditorGUILayout.EndVertical(); + + if (EditorGUI.EndChangeCheck() && isActive) + { + ApplyChanges(); + } + } + + private void ApplyChanges() + { + EditorUtility.SetDirty(depthColoringProperties); + + depthColoringProperties.ApplyValues(); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/DepthColoringPropertiesDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/DepthColoringPropertiesDrawer.cs.meta new file mode 100644 index 0000000..4e95625 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/DepthColoringPropertiesDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 605016f1af959104f98b4f8873abe8e0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/DepthColoringPropertiesDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers.meta new file mode 100644 index 0000000..10af649 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 377339d02577eb24793e9b80a10ae599 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AbstractEffectDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AbstractEffectDrawer.cs new file mode 100644 index 0000000..63775cd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AbstractEffectDrawer.cs @@ -0,0 +1,339 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public abstract class AbstractEffectDrawer + { + private const float HEIGHT_PER_LINE = 12.5f; + + protected string drawerID; + protected PropertiesConfig propertiesConfig; + protected AllIn13DEffectConfig effectConfig; + protected AllIn13DShaderInspectorReferences references; + protected int globalEffectIndex; + + public string ID + { + get + { + return drawerID; + } + } + + public AbstractEffectDrawer(AllIn13DShaderInspectorReferences references, PropertiesConfig propertiesConfig) + { + this.references = references; + this.propertiesConfig = propertiesConfig; + } + + public void Draw(PropertiesConfig propertiesConfig, AllIn13DEffectConfig effectConfig, int globalEffectIndex) + { + this.propertiesConfig = propertiesConfig; + this.effectConfig = effectConfig; + this.globalEffectIndex = globalEffectIndex; + + Draw(); + } + + protected virtual void Draw() + { + bool isShaderVariant = references.IsShaderVariant(); + bool areDependenciesMet = AreDependenciesMet(); + bool isEffectAvailableOnGlobalConfig = references.effectsProfileCollection.generalProfile.IsEffectEnabled(effectConfig.effectName); + bool isEffectAvailable = AllIn13DEffectConfig.IsEffectAvailable(effectConfig, references); + + bool groupEnabled = isEffectAvailable; + if (!isShaderVariant) + { + groupEnabled = groupEnabled && areDependenciesMet && isEffectAvailableOnGlobalConfig; + } + //bool groupEnabled = areDependenciesMet && isEffectAvailable && isEffectAvailableOnGlobalConfig /*|| (references.isShaderVariant && isEnabledInEffectsProfile)*/; + + //bool disableGroup = !groupEnabled; + + EditorGUILayout.BeginHorizontal(); + EditorGUI.BeginDisabledGroup(!groupEnabled); + EffectPropertyDrawer.DrawMainProperty(globalEffectIndex, effectConfig, references, isEffectAvailable, isEffectAvailableOnGlobalConfig); + EditorGUILayout.EndHorizontal(); + + bool isAnyPropertyVisible = IsAnyPropertyVisible(); + + if (isAnyPropertyVisible) + { + EditorGUILayout.BeginVertical(references.propertiesStyle); + DrawExtraData(); + DrawProperties(); + EditorGUILayout.EndVertical(); + } + EditorGUI.EndDisabledGroup(); + } + + private void DrawExtraData() + { + if (IsParentPropertyEnabled()) + { + string customMessage = effectConfig.GetCustomMessage(references.targetMatInfos); + if (!string.IsNullOrEmpty(customMessage)) + { + EditorGUILayout.BeginHorizontal(); + + int numLines = EditorUtils.GetNumLines(customMessage); + float heightField = numLines * HEIGHT_PER_LINE; + + if (!string.IsNullOrEmpty(effectConfig.docURL)) + { + if (GUILayout.Button("?", GUILayout.Width(heightField), GUILayout.Height(heightField))) + { + Application.OpenURL(effectConfig.docURL); + } + } + + EditorGUILayout.LabelField(customMessage, references.smallLabelStyle, GUILayout.Height(heightField)); + EditorGUILayout.EndHorizontal(); + } + } + } + + protected virtual void DrawProperties() + { + for (int i = 0; i < effectConfig.effectProperties.Count; i++) + { + EffectProperty effectProperty = effectConfig.effectProperties[i]; + DrawProperty(effectProperty, string.Empty, true); + } + } + + protected virtual void DrawProperty(EffectProperty effectProperty) + { + DrawProperty(effectProperty, true); + } + + protected virtual void DrawProperty(EffectProperty effectProperty, bool allowReset) + { + DrawProperty(effectProperty, string.Empty, allowReset); + } + + protected virtual void DrawProperty(EffectProperty effectProperty, string labelPrefix, bool allowReset) + { + if (IsEffectPropertyVisible(effectProperty, references.targetMatInfos)) + { + EffectProperty.PropertyType propertyType = effectProperty.GetPropertyType(); + MaterialProperty matProperty = references.matProperties[effectProperty.propertyIndex]; + + string propertyCustomValue = string.Empty; + if(references.IsShaderVariant() && effectProperty.IsPropertyWithKeywords()) + { + int index = 0; + bool isEnabled = references.IsEffectPropertyEnabled(effectProperty, ref index); + + if (isEnabled) + { + if (effectProperty.IsEnumProperty()) + { + propertyCustomValue = effectProperty.propertyKeywords[index]; + } + else + { + propertyCustomValue = string.Empty; + } + } + } + + EffectPropertyDrawer.DrawProperty( + materialProperty: matProperty, + labelPrefix: labelPrefix, + displayName: effectProperty.displayName, + customValue: propertyCustomValue, + allowReset: allowReset, + isKeywordProperty: effectProperty.IsPropertyWithKeywords(), + propertyType: effectProperty.GetPropertyType(), + references: references); + + //EffectPropertyDrawer.DrawProperty(effectProperty, labelPrefix, effectProperty.displayName, allowReset, effectProperty.IsPropertyWithKeywords(), references); + //EffectPropertyDrawer.DrawProperty(effectProperty, labelPrefix, allowReset, references); + } + } + + protected bool IsParentPropertyEnabled() + { + bool res = true; + + for (int matIdx = 0; matIdx < references.targetMatInfos.Length; matIdx++) + { + AbstractMaterialInfo targetMatInfo = references.targetMatInfos[matIdx]; + + bool thisMatParentPropertyEnabled = false; + for (int kwIdx = 0; kwIdx < effectConfig.keywords.Count; kwIdx++) + { + string kw = effectConfig.keywords[kwIdx].keyword; + if (targetMatInfo.IsKeywordEnabled(kw)) + { + thisMatParentPropertyEnabled = true; + break; + } + } + + res = res && thisMatParentPropertyEnabled; + } + + return res; + } + + protected bool IsAnyPropertyVisible() + { + bool res = false; + + bool parentPropertyEnabled = IsParentPropertyEnabled(); + if (parentPropertyEnabled) + { + for (int propIdx = 0; propIdx < effectConfig.effectProperties.Count; propIdx++) + { + EffectProperty effectProperty = effectConfig.effectProperties[propIdx]; + + res = IsEffectPropertyVisible(effectProperty, references.targetMatInfos); + if (res) + { + break; + } + } + } + + res = res || (parentPropertyEnabled && !string.IsNullOrEmpty(effectConfig.GetCustomMessage(references.targetMatInfos))); + + return res; + } + + protected bool IsEffectPropertyVisible(EffectProperty effectProperty, AbstractMaterialInfo[] targetMatInfos) + { + bool res = true; + + for (int i = 0; i < targetMatInfos.Length; i++) + { + res = res && IsEffectPropertyVisible(effectProperty, targetMatInfos[i]); + } + + return res; + } + + protected bool IsEffectPropertyVisible(EffectProperty effectProperty, AbstractMaterialInfo targetMatInfo) + { + bool res = false; + + bool anyIncompatibilities = false; + + for (int i = 0; i < effectProperty.incompatibleKeywords.Count; i++) + { + string incompatibleKw = effectProperty.incompatibleKeywords[i]; + if (targetMatInfo.IsKeywordEnabled(incompatibleKw)) + { + anyIncompatibilities = true; + } + } + + if (!anyIncompatibilities) + { + if (effectProperty.keywordsOp == KeywordsOp.OR) + { + for (int i = 0; i < effectProperty.keywords.Count; i++) + { + string keyword = effectProperty.keywords[i]; + + if (targetMatInfo.IsKeywordEnabled(keyword)) + { + res = true; + break; + } + } + } + else + { + res = true; + for (int i = 0; i < effectProperty.keywords.Count; i++) + { + string keyword = effectProperty.keywords[i]; + if (!targetMatInfo.IsKeywordEnabled(keyword)) + { + res = false; + break; + } + } + } + } + + return res; + } + + protected MaterialProperty FindPropertyByName(string propertyName) + { + MaterialProperty res = null; + + for (int i = 0; i < references.matProperties.Length; i++) + { + if (references.matProperties[i].name == propertyName) + { + res = references.matProperties[i]; + break; + } + } + + return res; + } + + protected int FindPropertyIndex(string propertyName) + { + int res = -1; + + for (int i = 0; i < references.matProperties.Length; i++) + { + if (references.matProperties[i].name == propertyName) + { + res = i; + break; + } + } + + return res; + } + + protected bool AreDependenciesMet() + { + bool res = true; + + if (!string.IsNullOrEmpty(effectConfig.dependentOnEffect)) + { + AllIn13DEffectConfig dependentEffect = propertiesConfig.FindEffectConfigByID(effectConfig.dependentOnEffect); + res = res && AllIn13DEffectConfig.IsEffectEnabled(dependentEffect, references); + } + + if (!string.IsNullOrEmpty(effectConfig.incompatibleWithEffectID)) + { + AllIn13DEffectConfig dependentEffect = propertiesConfig.FindEffectConfigByID(effectConfig.incompatibleWithEffectID); + res = res && !AllIn13DEffectConfig.IsEffectEnabled(dependentEffect, references); + } + + return res; + } + + protected bool IsShaderVariant() + { + bool res = true; + + for(int i = 0; i < references.targetMatInfos.Length; i++) + { + if (references.targetMatInfos[i].IsShaderVariant()) + { + res = false; + break; + } + } + + return res; + } + + public virtual void Refresh(AllIn13DShaderInspectorReferences references) + { + this.references = references; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AbstractEffectDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AbstractEffectDrawer.cs.meta new file mode 100644 index 0000000..a64aa07 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AbstractEffectDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 1fc7c21ef6e0e8b4c9333a9fdd7a4bb6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AbstractEffectDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AllIn13DShaderGradientDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AllIn13DShaderGradientDrawer.cs new file mode 100644 index 0000000..aa6e03d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AllIn13DShaderGradientDrawer.cs @@ -0,0 +1,43 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class AllIn13DShaderGradientDrawer : MaterialPropertyDrawer + { + private GradientEditorDrawer gradientEditorDrawer; + + private void RefreshReferences(MaterialProperty prop) + { + if(gradientEditorDrawer == null) + { + gradientEditorDrawer = new GradientEditorDrawer(); + } + } + + public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) + { + RefreshReferences(prop); + + Texture texValue = prop.textureValue; + + EditorGUI.BeginChangeCheck(); + Texture newTex = gradientEditorDrawer.Draw(position, texValue); + if (EditorGUI.EndChangeCheck()) + { + prop.textureValue = newTex; + } + } + + public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) + { + float res = 0f; + if(gradientEditorDrawer != null) + { + res = gradientEditorDrawer.GetPropertyHeight(); + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AllIn13DShaderGradientDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AllIn13DShaderGradientDrawer.cs.meta new file mode 100644 index 0000000..7d5331a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AllIn13DShaderGradientDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: aaf7449ec0a51804980a5d076861735c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/AllIn13DShaderGradientDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/ColorRampEffectDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/ColorRampEffectDrawer.cs new file mode 100644 index 0000000..acabdab --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/ColorRampEffectDrawer.cs @@ -0,0 +1,25 @@ +using UnityEditor; + +namespace AllIn13DShader +{ + public class ColorRampEffectDrawer : AbstractEffectDrawer + { + public ColorRampEffectDrawer(AllIn13DShaderInspectorReferences references, + PropertiesConfig propertiesConfig) : base(references, propertiesConfig) + { + this.drawerID = Constants.COLOR_RAMP_EFFECT_DRAWER_ID; + } + + protected override void DrawProperties() + { + for(int i = 0; i < effectConfig.effectProperties.Count; i++) + { + DrawProperty(effectConfig.effectProperties[i]); + if (i == 2) + { + EditorGUILayout.LabelField("*Set the Color Ramp Texture to Repeat Wrap Mode if using Tiling and/or Scroll Speed", references.smallLabelStyle); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/ColorRampEffectDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/ColorRampEffectDrawer.cs.meta new file mode 100644 index 0000000..75f7b46 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/ColorRampEffectDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 17130facc1b999348a0cbd8784766aba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/ColorRampEffectDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/GeneralEffectDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/GeneralEffectDrawer.cs new file mode 100644 index 0000000..97c91e4 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/GeneralEffectDrawer.cs @@ -0,0 +1,11 @@ +namespace AllIn13DShader +{ + public class GeneralEffectDrawer : AbstractEffectDrawer + { + public GeneralEffectDrawer(AllIn13DShaderInspectorReferences references, + PropertiesConfig propertiesConfig) : base(references, propertiesConfig) + { + this.drawerID = Constants.GENERAL_EFFECT_DRAWER_ID; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/GeneralEffectDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/GeneralEffectDrawer.cs.meta new file mode 100644 index 0000000..082f3cc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/GeneralEffectDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 8d0ce6e8dd172c346b1c817ec5065103 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/GeneralEffectDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/OutlineEffectDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/OutlineEffectDrawer.cs new file mode 100644 index 0000000..51762d3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/OutlineEffectDrawer.cs @@ -0,0 +1,35 @@ +using UnityEditor; + +namespace AllIn13DShader +{ + public class OutlineEffectDrawer : AbstractEffectDrawer + { + private MaterialProperty stencilRefMatProperty; + + public OutlineEffectDrawer(AllIn13DShaderInspectorReferences references, + PropertiesConfig propertiesConfig) : base(references, propertiesConfig) + { + this.drawerID = Constants.OUTLINE_DRAWER_ID; + + stencilRefMatProperty = FindPropertyByName("_StencilRef"); + } + + protected override void DrawProperties() + { + base.DrawProperties(); + + if (stencilRefMatProperty != null) + { + EffectPropertyDrawer.DrawProperty( + materialProperty: stencilRefMatProperty, + labelPrefix: string.Empty, + displayName: stencilRefMatProperty.displayName, + customValue: string.Empty, + allowReset: true, + isKeywordProperty: false, + propertyType: EffectProperty.PropertyType.BASIC, + references: references); + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/OutlineEffectDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/OutlineEffectDrawer.cs.meta new file mode 100644 index 0000000..c398328 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/OutlineEffectDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 6cc036b9a5e6daf40895576180575dd3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectDrawers/OutlineEffectDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectPropertyDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectPropertyDrawer.cs new file mode 100644 index 0000000..201007a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectPropertyDrawer.cs @@ -0,0 +1,370 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public static class EffectPropertyDrawer + { + public static void DrawMainProperty(int globalEffectIndex, + AllIn13DEffectConfig effectConfig, AllIn13DShaderInspectorReferences references, + bool isEffectAvailable, bool isEffectAvailableOnGlobalConfig) + { + EditorGUILayout.BeginHorizontal(); + + bool isShaderVariant = references.IsShaderVariant(); + string label = $"{globalEffectIndex}. {effectConfig.displayName}"; + + if (isEffectAvailableOnGlobalConfig || isShaderVariant) + { + switch (effectConfig.effectConfigType) + { + case EffectConfigType.EFFECT_TOGGLE: + DrawMainPropertyToggle(label, effectConfig, references, isShaderVariant); + break; + case EffectConfigType.EFFECT_ENUM: + DrawMainPropertyEnum(label, effectConfig, references, isEffectAvailable, isShaderVariant); + break; + } + } + else + { + int keywordSelectedIndex = 0; + references.IsEffectEnabled(effectConfig, ref keywordSelectedIndex); + + GUIContent guiContent = effectConfig.CreateGUIContent(globalEffectIndex, keywordSelectedIndex); + EditorGUILayout.LabelField(guiContent, GUILayout.Width(180f)); + EditorGUILayout.LabelField("Disabled in Active Effects List"); + } + + EditorGUILayout.EndHorizontal(); + } + + public static void DrawMainPropertyToggle(string label, + AllIn13DEffectConfig effectConfig, AllIn13DShaderInspectorReferences references, + bool isShaderVariant) + { + bool isEffectEnabled = AllIn13DEffectConfig.IsEffectEnabled(effectConfig, references); + + EditorGUI.BeginChangeCheck(); + + string tooltip = effectConfig.keywords[0].keyword + " (C#)"; + GUIContent guiContent = new GUIContent(label, tooltip); + + bool effectEnabledInAllMaterials = true; + bool effectDisabledInAllMaterials = true; + bool allMaterialsAreVariants = true; + for (int i = 0; i < references.targetMatInfos.Length; i++) + { + bool effectEnabledThisMat = AllIn13DEffectConfig.IsEffectEnabled(effectConfig, references.targetMatInfos[i]); + + effectEnabledInAllMaterials = effectEnabledInAllMaterials && effectEnabledThisMat; + effectDisabledInAllMaterials = effectDisabledInAllMaterials && !effectEnabledThisMat; + allMaterialsAreVariants = allMaterialsAreVariants && references.targetMatInfos[i].IsShaderVariant(); + } + + if (allMaterialsAreVariants) + { + GUILayout.Label(guiContent); + } + else + { + bool mixedValue = (!(effectEnabledInAllMaterials || effectDisabledInAllMaterials)) && references.targetMatInfos.Length > 1; + string style = mixedValue ? "ToggleMixed" : "Toggle"; + isEffectEnabled = GUILayout.Toggle(isEffectEnabled, guiContent, style); + } + if (EditorGUI.EndChangeCheck()) + { + for(int i = 0; i < references.targetMatInfos.Length; i++) + { + AbstractMaterialInfo matInfo = references.targetMatInfos[i]; + + if (isEffectEnabled) + { + AllIn13DEffectConfig.EnableEffect(effectConfig, references, matInfo); + } + else + { + AllIn13DEffectConfig.DisableEffect(effectConfig, matInfo); + } + } + + references.matProperties[effectConfig.keywordPropertyIndex].floatValue = isEffectEnabled ? 1f : 0f; + + EditorUtils.SetDirtyCurrentScene(); + + references.SetMaterialsDirty(); + } + } + + public static void DrawMainPropertyEnum(string label, + AllIn13DEffectConfig effectConfig, AllIn13DShaderInspectorReferences references, + bool isEffectAvailable, bool isShaderVariant) + { + int selectedIndex = 0; + //bool isEffectEnabled = AllIn13DEffectConfig.IsEffectEnabled(effectConfig, ref selectedIndex, references); + + + bool sameEnumValueInAllMaterials = references.IsEffectEnabled(effectConfig, ref selectedIndex); + //bool sameEnumValueInAllMaterials = true; + //for(int i = 0; i < references.targetMatInfos.Length; i++) + //{ + // int enumIdx = -1; + // AbstractMaterialInfo matInfo = references.targetMatInfos[i]; + + // bool effectEnabled = AllIn13DEffectConfig.IsEffectEnabled(effectConfig, ref enumIdx, matInfo); + + // if(i == 0) + // { + // selectedIndex = enumIdx; + // } + // else + // { + // sameEnumValueInAllMaterials = sameEnumValueInAllMaterials && (enumIdx == selectedIndex); + // } + //} + + + + + string tooltip = effectConfig.keywords[selectedIndex].keyword + " (C#)"; + GUIContent guiContent = new GUIContent(label, tooltip); + + + if (isShaderVariant) + { + if (isEffectAvailable) + { + EditorGUILayout.BeginHorizontal(references.propertiesStyle); + EditorGUILayout.LabelField(guiContent); + EditorGUILayout.LabelField(effectConfig.keywordsDisplayNames[selectedIndex]); + EditorGUILayout.EndHorizontal(); + } + else + { + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField(guiContent); + EditorGUILayout.EndHorizontal(); + } + } + else + { + EditorGUI.BeginChangeCheck(); + EditorGUI.showMixedValue = !sameEnumValueInAllMaterials; + selectedIndex = EditorGUILayout.Popup(guiContent, selectedIndex, effectConfig.keywordsDisplayNames); + EditorGUI.showMixedValue = false; + + if (EditorGUI.EndChangeCheck()) + { + for (int i = 0; i < references.targetMatInfos.Length; i++) + { + AbstractMaterialInfo matInfo = references.targetMatInfos[i]; + + if (selectedIndex >= 0) + { + AllIn13DEffectConfig.EnableEffectByIndex(effectConfig, selectedIndex, references, matInfo); + } + else + { + AllIn13DEffectConfig.DisableEffect(effectConfig, matInfo); + } + } + + references.matProperties[effectConfig.keywordPropertyIndex].floatValue = selectedIndex; + + EditorUtils.SetDirtyCurrentScene(); + + references.SetMaterialsDirty(); + } + } + } + + //public static void DrawProperty(int propertyIndex, string labelPrefix, bool allowReset, bool isKeywordProperty, AllIn13DShaderInspectorReferences references) + //{ + // MaterialProperty targetProperty = references.matProperties[propertyIndex]; + // DrawProperty( + // materialProperty: targetProperty, + // labelPrefix: labelPrefix, + // displayName: targetProperty.displayName, + // allowReset: allowReset, + // isKeywordProperty: isKeywordProperty, + // references: references); + //} + + //public static void DrawProperty(EffectProperty effectProperty, string labelPrefix, bool allowReset, AllIn13DShaderInspectorReferences references) + //{ + // DrawProperty(effectProperty.propertyIndex, labelPrefix, effectProperty.allowReset, effectProperty.IsPropertyWithKeywords(), references); + //} + + //public static void DrawProperty(EffectProperty effectProperty, AllIn13DShaderInspectorReferences references) + //{ + // DrawProperty(propertyIndex: effectProperty.propertyIndex, isKeywordProperty: effectProperty.IsPropertyWithKeywords(), references: references); + //} + + //public static void DrawProperty(int propertyIndex, bool isKeywordProperty, AllIn13DShaderInspectorReferences references) + //{ + // DrawProperty(propertyIndex, string.Empty, true, isKeywordProperty, references); + //} + + //public static void DrawProperty(MaterialProperty materialProperty, AllIn13DShaderInspectorReferences references) + //{ + // DrawProperty(materialProperty, false, references); + //} + + //public static void DrawProperty(MaterialProperty materialProperty, bool isKeywordProperty, AllIn13DShaderInspectorReferences references) + //{ + // DrawProperty( + // materialProperty: materialProperty, + // labelPrefix: string.Empty, + // displayName: materialProperty.displayName, + // allowReset: true, + // isKeywordProperty: isKeywordProperty, + // references: references); + //} + + //public static void DrawProperty(MaterialProperty materialProperty, bool allowReset, bool isKeywordProperty, AllIn13DShaderInspectorReferences references) + //{ + // DrawProperty( + // materialProperty: materialProperty, + // labelPrefix: string.Empty, + // displayName: materialProperty.displayName, + // allowReset: allowReset, + // isKeywordProperty: isKeywordProperty, + // references: references); + //} + + //public static void DrawProperty( + // MaterialProperty materialProperty, + // string labelPrefix, + // bool allowReset, + // bool isKeywordProperty, + // AllIn13DShaderInspectorReferences references) + //{ + // DrawProperty( + // materialProperty: materialProperty, + // labelPrefix: labelPrefix, + // displayName: materialProperty.displayName, + // allowReset: allowReset, + // isKeywordProperty: isKeywordProperty, + // references: references); + //} + + //public static void DrawPropertyCustomValue( + // EffectProperty effectProperty, + // string labelPrefix, + // string displayName, + // bool allowReset, + // bool isKeywordProperty, + // AllIn13DShaderInspectorReferences references) + //{ + // MaterialProperty materialProperty = references.matProperties[effectProperty.propertyIndex]; + // string label = $"{labelPrefix} {displayName}"; + // string tooltip = materialProperty.name + "(C#)"; + + // EditorGUILayout.BeginHorizontal(); + + // DrawShaderProperty(materialProperty: materialProperty, label: label, tooltip: tooltip, isKeywordProperty: isKeywordProperty, references: references); + // if (allowReset) + // { + // DrawResetButton(materialProperty, references); + // } + + // EditorGUILayout.EndHorizontal(); + //} + + public static void DrawProperty( + MaterialProperty materialProperty, + string labelPrefix, + string displayName, + string customValue, + bool allowReset, + bool isKeywordProperty, + EffectProperty.PropertyType propertyType, + AllIn13DShaderInspectorReferences references) + { + string label = $"{labelPrefix} {displayName}"; + string tooltip = materialProperty.name + "(C#)"; + + EditorGUILayout.BeginHorizontal(); + + bool isShaderVariant = references.IsShaderVariant(); + + if(isShaderVariant && isKeywordProperty) + { + DrawShaderPropertyCustomValue(label: label, tooltip: tooltip, customValue: customValue, isKeywordProperty: isKeywordProperty, propertyType: propertyType, references: references); + } + else + { + DrawShaderProperty(materialProperty: materialProperty, label: label, tooltip: tooltip, isKeywordProperty: isKeywordProperty, references: references); + if (allowReset) + { + DrawResetButton(materialProperty, references); + } + } + + EditorGUILayout.EndHorizontal(); + } + + private static void DrawShaderProperty( + MaterialProperty materialProperty, + string label, + string tooltip, + bool isKeywordProperty, + AllIn13DShaderInspectorReferences references) + { + GUIContent propertyLabel = new GUIContent(); + propertyLabel.text = label; + propertyLabel.tooltip = tooltip; + + EditorGUI.BeginChangeCheck(); + references.editorMat.ShaderProperty(materialProperty, propertyLabel); + if (EditorGUI.EndChangeCheck()) + { + if (isKeywordProperty) + { + references.RefreshMaterialKeywords(); + } + } + } + + private static void DrawShaderPropertyCustomValue( + string label, + string tooltip, + string customValue, + bool isKeywordProperty, + EffectProperty.PropertyType propertyType, + AllIn13DShaderInspectorReferences references) + { + EditorGUILayout.BeginHorizontal(); + GUIContent propertyLabel = new GUIContent(); + propertyLabel.text = label; + propertyLabel.tooltip = tooltip; + + if(propertyType == EffectProperty.PropertyType.TOGGLE) + { + EditorGUILayout.Toggle(propertyLabel, true); + } + else + { + EditorGUILayout.LabelField(propertyLabel); + EditorGUILayout.LabelField(customValue); + } + + EditorGUILayout.EndHorizontal(); + } + + public static void DrawResetButton(MaterialProperty targetProperty, AllIn13DShaderInspectorReferences references) + { + GUIContent resetButtonLabel = new GUIContent(); + resetButtonLabel.text = "R"; + resetButtonLabel.tooltip = "Resets to default value"; + if (GUILayout.Button(resetButtonLabel, GUILayout.Width(20))) + { + for (int i = 0; i < references.targetMatInfos.Length; i++) + { + AbstractMaterialInfo matInfo = references.targetMatInfos[i]; + AllIn13DEffectConfig.ResetProperty(targetProperty, references, matInfo); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectPropertyDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectPropertyDrawer.cs.meta new file mode 100644 index 0000000..620331f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectPropertyDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: edd8e2faf4f408743829655503b71b17 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/EffectPropertyDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/GlobalPropertiesDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GlobalPropertiesDrawer.cs new file mode 100644 index 0000000..151f9b6 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GlobalPropertiesDrawer.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class GlobalPropertiesDrawer + { + private List globalPropertiesIndices; + private AllIn13DShaderInspectorReferences references; + + public GlobalPropertiesDrawer() + { + } + + public void Draw(List globalPropertiesIndices, AllIn13DShaderInspectorReferences references) + { + this.globalPropertiesIndices = globalPropertiesIndices; + this.references = references; + + GUILayout.Label("Global Properties", references.bigLabelStyle); + + EditorGUILayout.BeginVertical(references.propertiesStyle); + for (int i = 0; i < globalPropertiesIndices.Count; i++) + { + MaterialProperty matProperty = references.matProperties[globalPropertiesIndices[i]]; + + EffectPropertyDrawer.DrawProperty( + materialProperty: matProperty, + labelPrefix: string.Empty, + displayName: matProperty.displayName, + customValue: string.Empty, + allowReset: true, + isKeywordProperty: false, + propertyType: EffectProperty.PropertyType.BASIC, + references: references); + } + + EditorGUILayout.EndVertical(); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/GlobalPropertiesDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GlobalPropertiesDrawer.cs.meta new file mode 100644 index 0000000..ec70825 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GlobalPropertiesDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 55fc5c9db4641f54a912ca07e7d764f8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/GlobalPropertiesDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientCreatorDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientCreatorDrawer.cs new file mode 100644 index 0000000..920cae0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientCreatorDrawer.cs @@ -0,0 +1,107 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class GradientCreatorDrawer + { + private GradientCreatorTool gradientCreatorTool; + private CommonStyles commonStyles; + + private Texture2D GradientTex + { + get + { + return gradientCreatorTool.gradientTex; + } + set + { + gradientCreatorTool.gradientTex = value; + } + } + + private Gradient Grad + { + get + { + return gradientCreatorTool.gradient; + } + set + { + gradientCreatorTool.gradient = value; + } + } + + private TextureSizes GradientSizes + { + get + { + return gradientCreatorTool.gradientSizes; + } + set + { + gradientCreatorTool.gradientSizes = value; + } + } + + private FilterMode GradientFiltering + { + get + { + return gradientCreatorTool.gradientFiltering; + } + set + { + gradientCreatorTool.gradientFiltering = value; + } + } + + public GradientCreatorDrawer(GradientCreatorTool gradientCreatorTool, CommonStyles commonStyles) + { + this.gradientCreatorTool = gradientCreatorTool; + this.commonStyles = commonStyles; + } + + public void Draw() + { + GUILayout.Label("Color Gradient Creator", commonStyles.bigLabel); + GUILayout.Space(20); + GUILayout.Label("This feature can be used to create textures for the Color Ramp Effect", EditorStyles.boldLabel); + + EditorGUI.BeginChangeCheck(); + Grad = EditorGUILayout.GradientField("Color Gradient: ", Grad, GUILayout.Height(25), GUILayout.MaxWidth(CommonStyles.BUTTON_WIDTH)); + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Texture Size:", GUILayout.MaxWidth(145)); + GradientSizes = (TextureSizes)EditorGUILayout.EnumPopup(GradientSizes, GUILayout.MaxWidth(200)); + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("New Textures Filtering: ", GUILayout.MaxWidth(145)); + GradientFiltering = (FilterMode)EditorGUILayout.EnumPopup(GradientFiltering, GUILayout.MaxWidth(200)); + } + EditorGUILayout.EndHorizontal(); + + bool gradientChanged = EditorGUI.EndChangeCheck(); + if (gradientChanged) + { + gradientCreatorTool.CreateGradientTexture(); + } + + GUILayout.Space(20); + GUILayout.Label("Select the folder where new Color Gradient Textures will be saved", EditorStyles.boldLabel); + + GlobalConfiguration.instance.GradientSavePath = EditorUtils.DrawSelectorFolder(GlobalConfiguration.instance.GradientSavePath, /*AllIn13DShaderConfig.GRADIENT_SAVE_PATH_DEFAULT,*/ "Gradients"); + if (Directory.Exists(GlobalConfiguration.instance.GradientSavePath)) + { + if (GUILayout.Button("Save Color Gradient Texture", GUILayout.MaxWidth(CommonStyles.BUTTON_WIDTH))) + { + EditorUtils.SaveTextureAsPNG(GlobalConfiguration.instance.GradientSavePath, "ColorGradient", "Gradient", GradientTex, GradientFiltering, + TextureImporterType.Default, TextureWrapMode.Clamp); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientCreatorDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientCreatorDrawer.cs.meta new file mode 100644 index 0000000..f8bbfef --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientCreatorDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 53d536ed22c0b4d4e8472402997463dd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientCreatorDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientEditorDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientEditorDrawer.cs new file mode 100644 index 0000000..5045280 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientEditorDrawer.cs @@ -0,0 +1,332 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class GradientEditorDrawer + { + private const float OFFSET = 5f; + + private Gradient gradient; + private Rect lastRect; + private Texture2D previewTex; + private GradientCreatorTool gradientCreatorTool; + + private bool createGradientToggle; + private bool textureSaved; + private bool usingPreviewTex; + private bool isModifyingExistingTexture; + + private Texture lastSavedTexture; + private Gradient lastGradient; + + private GradientTexture gradientTextureAsset; + + private void RefreshReferences(Texture lastTexture) + { + if (gradient == null) + { + gradient = new Gradient(); + } + + if (previewTex == null) + { + previewTex = new Texture2D(128, 128); + } + + if (gradientCreatorTool == null) + { + gradientCreatorTool = new GradientCreatorTool(); + } + + if (lastSavedTexture == null) + { + lastSavedTexture = lastTexture; + } + + if (lastGradient == null) + { + lastGradient = new Gradient(); + } + } + + private Texture RefreshGradientState(Texture texValue) + { + Texture res = texValue; + + if (createGradientToggle) + { + lastSavedTexture = texValue; + + isModifyingExistingTexture = EditorUtils.IsProjectAsset(lastSavedTexture); + + this.gradientTextureAsset = GradientCreatorTool.FindGradientTexureByTex(texValue); + if (this.gradientTextureAsset != null) + { + GradientCreatorTool.CopyGradient(gradientTextureAsset.gradient, gradient); + } + else + { + if (texValue != null) + { + gradient = CreateGradientFromTexture(texValue); + } + else + { + gradient = new Gradient(); + } + } + + previewTex = gradientCreatorTool.CreateGradientTexture(gradient); + res = previewTex; + } + else + { + GradientCreatorTool.CopyGradient(gradient, lastGradient); + previewTex = null; + res = lastSavedTexture; + } + + return res; + } + + private Gradient CreateGradientFromTexture(Texture texSource) + { + int width = texSource.width; + int height = texSource.height; + + RenderTexture renderTex = RenderTexture.GetTemporary( + width, + height, + 0, + RenderTextureFormat.Default, + RenderTextureReadWrite.Linear); + + Graphics.Blit(texSource, renderTex); + RenderTexture previous = RenderTexture.active; + RenderTexture.active = renderTex; + Texture2D readableText = new Texture2D(texSource.width, texSource.height); + readableText.filterMode = texSource.filterMode; + readableText.wrapMode = texSource.wrapMode; + readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0); + readableText.Apply(); + RenderTexture.active = previous; + RenderTexture.ReleaseTemporary(renderTex); + + + Gradient res = new Gradient(); + List gradientColorKeys = new List(); + + int numSamples = 5; + float step = (((float)width) / numSamples) / width; + + Vector2 sampleUV = Vector2.zero; + sampleUV.y = renderTex.height * 0.5f; + for (int i = 0; i < numSamples; i++) + { + Color col = readableText.GetPixelBilinear(sampleUV.x, sampleUV.y); + gradientColorKeys.Add(new GradientColorKey(col, sampleUV.x)); + + sampleUV.x += step; + } + + Color lastCol = readableText.GetPixelBilinear(sampleUV.x, sampleUV.y); + gradientColorKeys.Add(new GradientColorKey(lastCol, sampleUV.x)); + + res.colorKeys = gradientColorKeys.ToArray(); + res.mode = GradientMode.Blend; + + return res; + } + + public Texture Draw(Rect position, Texture gradientTexture) + { + RefreshReferences(gradientTexture); + + lastRect = position; + + Texture texValue = gradientTexture; + + EditorGUI.BeginChangeCheck(); + + if (createGradientToggle && texValue == null) + { + texValue = lastSavedTexture; + createGradientToggle = false; + } + + texValue = DrawTextureField(texValue, 60f, "Color ramp texture"); + bool changes = EditorGUI.EndChangeCheck(); + if (changes) + { + createGradientToggle = false; + lastSavedTexture = texValue; + } + + + EditorGUI.BeginChangeCheck(); + DrawCreateGradientToggle(15f, "Create Gradient"); + bool createGradientToggleChanged = EditorGUI.EndChangeCheck(); + if (createGradientToggleChanged) + { + texValue = RefreshGradientState(texValue); + } + + EditorGUI.BeginChangeCheck(); + if (createGradientToggle) + { + texValue = DrawGradientField(40f, "Gradient", texValue); + } + + EditorGUI.showMixedValue = false; + bool gradientFieldChanged = EditorGUI.EndChangeCheck(); + if (gradientFieldChanged && !textureSaved) + { + previewTex = gradientCreatorTool.CreateGradientTexture(TextureSizes._256, FilterMode.Bilinear, gradient); + texValue = previewTex; + + usingPreviewTex = true; + } + + textureSaved = false; + + return texValue; + } + + private Texture DrawTextureField(Texture tex, float height, string label) + { + Rect rect = new Rect(lastRect); + rect.height = height; + + GUIStyle labelStyle = EditorStyles.label; + labelStyle.alignment = TextAnchor.UpperLeft; + + Rect labelRect = new Rect(rect); + labelRect.width = 200f; + EditorGUI.LabelField(labelRect, new GUIContent(label), labelStyle); + + GUIStyle textureStyle = EditorStyles.objectField; + textureStyle.alignment = TextAnchor.MiddleLeft; + + Rect textureRect = new Rect(rect); + textureRect.width = height; + textureRect.height = height; + textureRect.x = rect.width - textureRect.width - 10f; + + Texture res = (Texture)EditorGUI.ObjectField(textureRect, tex, typeof(Texture), false); + lastRect.y += height; + + return res; + } + + private Texture DrawGradientField(float height, string label, Texture texValue) + { + Texture res = texValue; + + Rect rect = new Rect(lastRect); + rect.height = height; + rect.y += height * 0.5f; + + float createButtonWidth = 100f; + + GUIStyle labelStyle = EditorStyles.label; + labelStyle.alignment = TextAnchor.UpperLeft; + Rect labelRect = new Rect(rect); + labelRect.width = 200f; + EditorGUI.LabelField(labelRect, new GUIContent(label), labelStyle); + + GUIStyle textureStyle = EditorStyles.objectField; + textureStyle.alignment = TextAnchor.MiddleLeft; + + Rect gradientAndButtonRect = new Rect(rect); + gradientAndButtonRect.width = rect.width - labelRect.width; + gradientAndButtonRect.height = rect.height; + gradientAndButtonRect.x = labelRect.x + labelRect.width; + + Rect gradientRect = new Rect(gradientAndButtonRect); + gradientRect.width = gradientAndButtonRect.width * 0.5f; + gradientRect.height = rect.height * 0.5f; + gradientRect.x = rect.x + rect.width - gradientRect.width - (createButtonWidth * 2f) - 10f; + gradient = EditorGUI.GradientField(gradientRect, gradient); + + Rect createButtonRect = new Rect(gradientAndButtonRect); + createButtonRect.width = createButtonWidth; + createButtonRect.height = gradientRect.height; + createButtonRect.x = gradientRect.x + gradientRect.width + 10f; + + Rect modifyButtonRect = new Rect(createButtonRect); + modifyButtonRect.x = createButtonRect.x + createButtonRect.width + 10f; + + if (GUI.Button(createButtonRect, "Save Texture")) + { + res = ChangeTextureOnDisk(true); + } + + EditorGUI.BeginDisabledGroup(!isModifyingExistingTexture || gradientTextureAsset == null); + if (GUI.Button(modifyButtonRect, "Overwrite")) + { + res = ChangeTextureOnDisk(false); + } + EditorGUI.EndDisabledGroup(); + + lastRect.y += height + OFFSET; + + if (usingPreviewTex && !textureSaved) + { + Rect helpBoxRect = new Rect(lastRect); + helpBoxRect.height = 40f; + EditorGUI.HelpBox(helpBoxRect, "Texture is not saved! Click on Save Texture to save it", MessageType.Warning); + + lastRect.y += helpBoxRect.height + OFFSET; + } + + return res; + } + + private Texture ChangeTextureOnDisk(bool createNew) + { + gradientCreatorTool.CreateGradientTexture(gradient); + Texture savedTex = gradientCreatorTool.SaveGradientTexture(gradientTextureAsset, createNew); + + Texture res = savedTex; + lastSavedTexture = savedTex; + + textureSaved = true; + usingPreviewTex = false; + createGradientToggle = false; + + gradientTextureAsset = null; + + return res; + } + + private void DrawCreateGradientToggle(float height, string label) + { + Rect rect = new Rect(lastRect); + rect.height = height; + + Rect toggleRect = new Rect(rect); + + createGradientToggle = EditorGUI.ToggleLeft(toggleRect, label, createGradientToggle); + + lastRect.y += height; + } + + public float GetPropertyHeight() + { + float res = 80f; + + if (createGradientToggle) + { + res += 45f; + if (usingPreviewTex) + { + res += 40f; + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientEditorDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientEditorDrawer.cs.meta new file mode 100644 index 0000000..e9d4352 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientEditorDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 42eeae2ae0fe6674786f324f6b74294c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/GradientEditorDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorDrawer.cs new file mode 100644 index 0000000..3c6a9c3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorDrawer.cs @@ -0,0 +1,124 @@ +using System.IO; +using UnityEditor; +using UnityEngine; +using static AllIn13DShader.NoiseCreatorTool; + +namespace AllIn13DShader +{ + public class NoiseCreatorDrawer + { + private NoiseCreatorTool noiseCreatorTool; + private CommonStyles commonStyles; + + private NoiseCreatorValues Values + { + get + { + return noiseCreatorTool.values; + } + } + + public NoiseCreatorDrawer(NoiseCreatorTool noiseCreatorTool, CommonStyles commonStyles) + { + this.noiseCreatorTool = noiseCreatorTool; + this.commonStyles = commonStyles; + } + + public void Draw() + { + GUILayout.Label("Tileable Noise Creator", commonStyles.bigLabel); + GUILayout.Space(20); + + EditorGUILayout.BeginHorizontal(); + { + EditorGUILayout.BeginVertical(GUILayout.MaxWidth(550)); + { + if (Values.noisePreview == null) + { + GUILayout.Label("*Change a property to start editing a Noise texture", EditorStyles.boldLabel); + } + + EditorGUI.BeginChangeCheck(); + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Noise Type:", GUILayout.MaxWidth(145)); + Values.noiseType = (NoiseTypes)EditorGUILayout.EnumPopup(Values.noiseType, GUILayout.MaxWidth(200)); + } + EditorGUILayout.EndHorizontal(); + if (EditorGUI.EndChangeCheck()) + { + noiseCreatorTool.NoiseSetMaterial(); + noiseCreatorTool.CheckCreationNoiseTextures(); + noiseCreatorTool.UpdateNoiseMatAndRender(); + } + + EditorGUI.BeginChangeCheck(); + if (Values.isFractalNoise) + { + EditorUtils.TextureEditorFloatParameter("Scale X", ref Values.noiseScaleX, 0.1f, 50f, 4f); + if (!Values.noiseSquareScale) EditorUtils.TextureEditorFloatParameter("Scale Y", ref Values.noiseScaleY, 0.1f, 50f, 4f); + } + else + { + EditorUtils.TextureEditorFloatParameter("Scale X", ref Values.noiseScaleX, 0.1f, 50f, 10f); + if (!Values.noiseSquareScale) EditorUtils.TextureEditorFloatParameter("Scale Y", ref Values.noiseScaleY, 0.1f, 50f, 10f); + } + Values.noiseSquareScale = EditorGUILayout.Toggle("Square Scale?", Values.noiseSquareScale, GUILayout.MaxWidth(200)); + if (Values.noiseSquareScale) Values.noiseScaleY = Values.noiseScaleX; + if (Values.noiseType == NoiseTypes.Fractal) EditorUtils.TextureEditorFloatParameter("Fractal Amount", ref Values.noiseFractalAmount, 1f, 10f, 8f); + else if (Values.noiseType == NoiseTypes.Perlin) EditorUtils.TextureEditorFloatParameter("Fractal Amount", ref Values.noiseFractalAmount, 1f, 10f, 1f); + else if (Values.noiseType == NoiseTypes.Billow) EditorUtils.TextureEditorFloatParameter("Fractal Amount", ref Values.noiseFractalAmount, 1f, 10f, 4f); + else EditorUtils.TextureEditorFloatParameter("Jitter", ref Values.noiseJitter, 0.0f, 2f, 1f); + EditorUtils.TextureEditorFloatParameter("Contrast", ref Values.noiseContrast, 0.1f, 10f, 1f); + EditorUtils.TextureEditorFloatParameter("Brightness", ref Values.noiseBrightness, -1f, 1f, 0f); + EditorUtils.TextureEditorIntParameter("Random Seed", ref Values.noiseSeed, 0, 100, 0); + Values.noiseInverted = EditorGUILayout.Toggle("Inverted?", Values.noiseInverted); + + if (EditorGUI.EndChangeCheck()) + { + if (Values.noiseMaterial == null) + { + noiseCreatorTool.NoiseSetMaterial(); + } + noiseCreatorTool.CheckCreationNoiseTextures(); + + noiseCreatorTool.UpdateNoiseMatAndRender(); + } + + GUILayout.Space(20); + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Noise Size:", GUILayout.MaxWidth(145)); + Values.noiseSize = (TextureSizes)EditorGUILayout.EnumPopup(Values.noiseSize, GUILayout.MaxWidth(200)); + } + EditorGUILayout.EndHorizontal(); + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("New Noise Filtering: ", GUILayout.MaxWidth(145)); + Values.noiseFiltering = (FilterMode)EditorGUILayout.EnumPopup(Values.noiseFiltering, GUILayout.MaxWidth(200)); + } + EditorGUILayout.EndHorizontal(); + } + EditorGUILayout.EndVertical(); + + if (Values.noisePreview != null) GUILayout.Label(Values.noisePreview, GUILayout.MaxWidth(450), GUILayout.MaxHeight(450)); + } + EditorGUILayout.EndHorizontal(); + + + GUILayout.Space(20); + GUILayout.Label("Select the folder where new Noise Textures will be saved", EditorStyles.boldLabel); + GlobalConfiguration.instance.NoiseSavePath = EditorUtils.DrawSelectorFolder(GlobalConfiguration.instance.NoiseSavePath, /*AllIn13DShaderConfig.NOISES_SAVE_PATH_DEFAULT,*/ "Noises"); + + if (Directory.Exists(GlobalConfiguration.instance.NoiseSavePath) && Values.noisePreview != null) + { + if (GUILayout.Button("Save Noise Texture", GUILayout.MaxWidth(CommonStyles.BUTTON_WIDTH))) + { + noiseCreatorTool.CreateNoiseTex(); + EditorUtils.SaveTextureAsPNG(GlobalConfiguration.instance.NoiseSavePath, "Noise", "Noises", + Values.finalNoiseTex, Values.noiseFiltering, TextureImporterType.Default, TextureWrapMode.Clamp); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorDrawer.cs.meta new file mode 100644 index 0000000..202091f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: f1d0e6ca131aebb45a4e398281fa7db3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorValues.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorValues.cs new file mode 100644 index 0000000..4851553 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorValues.cs @@ -0,0 +1,62 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class NoiseCreatorValues + { + public Texture2D noisePreview = null; + public Texture2D finalNoiseTex = null; + + public RenderTexture noiseRenderTarget = null; + public Material noiseMaterial; + + public float noiseScaleX = 10f; + public float noiseScaleY = 10f; + public float noiseContrast = 1f; + public float noiseBrightness = 0f; + + public float noiseFractalAmount = 1f; + public float noiseJitter = 1f; + public int noiseSeed = 0; + + public bool noiseSquareScale = false; + public bool noiseInverted = false; + public bool isFractalNoise = false; + + public NoiseCreatorTool.NoiseTypes noiseType; + + public TextureSizes noiseSize; + public FilterMode noiseFiltering; + + public NoiseCreatorValues() + { + SetDefault(); + } + + public void SetDefault() + { + noisePreview = null; + noiseRenderTarget = null; + finalNoiseTex = null; + + noiseMaterial = null; + noiseScaleX = 10f; + noiseScaleY = 10f; + noiseContrast = 1f; + noiseBrightness = 0f; + + noiseFractalAmount = 1f; + noiseJitter = 1f; + noiseSeed = 0; + + noiseSquareScale = false; + noiseInverted = false; + isFractalNoise = false; + + noiseType = NoiseCreatorTool.NoiseTypes.Voronoi; + + noiseSize = TextureSizes._512; + noiseFiltering = FilterMode.Bilinear; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorValues.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorValues.cs.meta new file mode 100644 index 0000000..a13a1fc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorValues.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 14c147009aa5dae418a84b61107ada3c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/NoiseCreatorValues.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapCreatorDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapCreatorDrawer.cs new file mode 100644 index 0000000..a8f91b4 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapCreatorDrawer.cs @@ -0,0 +1,138 @@ +using System; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class NormalMapCreatorDrawer + { + private NormalMapCreatorTool normalMapCreatorTool; + private CommonStyles commonStyles; + private Action repaintAction; + + private Texture2D TargetNormalImage + { + get + { + return normalMapCreatorTool.targetNormalImage; + } + set + { + normalMapCreatorTool.targetNormalImage = value; + } + } + + private float NormalStrength + { + get + { + return normalMapCreatorTool.normalStrength; + } + set + { + normalMapCreatorTool.normalStrength = value; + } + } + + private int NormalSmoothing + { + get + { + return normalMapCreatorTool.normalSmoothing; + } + set + { + normalMapCreatorTool.normalSmoothing = value; + } + } + + private bool InvertNormals{ get; set; } + + private int IsComputingNormals + { + get + { + return normalMapCreatorTool.isComputingNormals; + } + set + { + normalMapCreatorTool.isComputingNormals = value; + } + } + + public NormalMapCreatorDrawer(NormalMapCreatorTool normalMapCreatorTool, CommonStyles commonStyles, Action repaintAction) + { + this.normalMapCreatorTool = normalMapCreatorTool; + this.commonStyles = commonStyles; + this.repaintAction = repaintAction; + } + + public void Draw() + { + GUILayout.Label("Normal/Distortion Map Creator", commonStyles.bigLabel); + GUILayout.Space(20); + + GUILayout.Label("Select the folder where new Normal Maps will be saved when the Create Normal Map button of the asset component is pressed", EditorStyles.boldLabel); + + GlobalConfiguration.instance.NormalMapSavePath = EditorUtils.DrawSelectorFolder(GlobalConfiguration.instance.NormalMapSavePath, /*AllIn13DShaderConfig.NORMAL_MAP_SAVE_PATH_DEFAULT,*/ "Normal Maps Folder"); + + GUILayout.Label("Assign a texture you want to create a normal map from. Choose the normal map settings and press the 'Create And Save Normal Map' button", EditorStyles.boldLabel); + TargetNormalImage = (Texture2D)EditorGUILayout.ObjectField("Target Image", TargetNormalImage, typeof(Texture2D), false, GUILayout.MaxWidth(225)); + + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Normal Strength:", GUILayout.MaxWidth(150)); + NormalStrength = EditorGUILayout.Slider(NormalStrength, 1f, 20f, GUILayout.MaxWidth(400)); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Normal Smoothing:", GUILayout.MaxWidth(150)); + NormalSmoothing = EditorGUILayout.IntSlider(NormalSmoothing, 0, 3, GUILayout.MaxWidth(400)); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Invert Normal Direction:", GUILayout.MaxWidth(150)); + InvertNormals = EditorGUILayout.Toggle(InvertNormals, GUILayout.MaxWidth(400)); + } + EditorGUILayout.EndHorizontal(); + + if (IsComputingNormals == 0) + { + if (TargetNormalImage != null) + { + if (GUILayout.Button("Create And Save Normal Map", GUILayout.MaxWidth(CommonStyles.BUTTON_WIDTH))) + { + IsComputingNormals = 1; + return; + } + } + else + { + GUILayout.Label("Add a Target Image to use this feature", EditorStyles.boldLabel); + } + } + else + { + GUILayout.Label("Normal Map is currently being created, be patient", EditorStyles.boldLabel, GUILayout.Height(40)); + repaintAction(); + + IsComputingNormals++; + if(IsComputingNormals > 5) + { + EditorUtils.SetTextureReadWrite(AssetDatabase.GetAssetPath(TargetNormalImage), true); + + Texture2D normalMapToSave = normalMapCreatorTool.CreateNormalMap(InvertNormals); + EditorUtils.SaveTextureAsPNG(GlobalConfiguration.instance.NormalMapSavePath, "NormalMap", "Normal Map", normalMapToSave, FilterMode.Bilinear, TextureImporterType.NormalMap, TextureWrapMode.Repeat); + + IsComputingNormals = 0; + } + } + + GUILayout.Label("*This process will freeze the editor for some seconds, larger images will take longer", EditorStyles.boldLabel); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapCreatorDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapCreatorDrawer.cs.meta new file mode 100644 index 0000000..ab79da5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapCreatorDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 6304f118428d4744c8f82a134c469288 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapCreatorDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapEffectDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapEffectDrawer.cs new file mode 100644 index 0000000..29231d6 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapEffectDrawer.cs @@ -0,0 +1,67 @@ +using UnityEngine; +using UnityEditor; + +namespace AllIn13DShader +{ + public class NormalMapEffectDrawer : AbstractEffectDrawer + { + private int mainTexPropertyIndex; + private EffectProperty effectPropNormalMap; + private EffectProperty effectPropNormalStrength; + + private bool invertNormalMapDirection = false; + private float normalCreateStrength = 2.0f; + private float normalCreateSmooth = 1.0f; + + public NormalMapEffectDrawer(AllIn13DShaderInspectorReferences references, + PropertiesConfig propertiesConfig) : base(references, propertiesConfig) + { + drawerID = Constants.NORMAL_MAP_EFFECT_DRAWER_ID; + + effectConfig = propertiesConfig.FindEffectConfigByID("NORMAL_MAP"); + + mainTexPropertyIndex = FindPropertyIndex("_MainTex"); + effectPropNormalMap = effectConfig.FindEffectPropertyByName("_NormalMap"); + effectPropNormalStrength = effectConfig.FindEffectPropertyByName("_NormalStrength"); + } + + protected override void DrawProperties() + { + DrawProperty(effectPropNormalMap); + DrawProperty(effectPropNormalStrength); + + EditorUtils.DrawLine(Color.grey, 1, 3); + EditorGUILayout.LabelField("Normal Map Creation", EditorStyles.boldLabel); + + EditorUtils.TextureEditorFloatParameter("Strength", ref normalCreateStrength, 0.1f, 8.0f, 2.0f); + EditorUtils.TextureEditorFloatParameter("Smooth", ref normalCreateSmooth, 0.0f, 5.0f, 1.0f); + invertNormalMapDirection = EditorGUILayout.Toggle("Invert Normal Direction", invertNormalMapDirection); + + GUILayout.Space(2); + if(GUILayout.Button("Create Normal Map Texture")) CreateNormalMap(); + } + + private void CreateNormalMap() + { + Texture2D sourceTexture = references.matProperties[mainTexPropertyIndex].textureValue as Texture2D; + if(sourceTexture == null) + { + EditorUtility.DisplayDialog("Error", "No Main Tex found. Please assign it first", "OK"); + return; + } + EditorUtils.SetTextureReadWrite(AssetDatabase.GetAssetPath(sourceTexture), true); + NormalMapCreatorTool normalMapCreatorTool = new NormalMapCreatorTool + { + targetNormalImage = sourceTexture, + normalStrength = normalCreateStrength, + normalSmoothing = Mathf.RoundToInt(normalCreateSmooth), + isComputingNormals = 1 + }; + Texture2D normalMapToSave = normalMapCreatorTool.CreateNormalMap(invertNormalMapDirection); + Texture savedTex = EditorUtils.SaveTextureAsPNG(GlobalConfiguration.instance.NormalMapSavePath, "NormalMap", "Normal Map", normalMapToSave, FilterMode.Bilinear, TextureImporterType.NormalMap, TextureWrapMode.Repeat); + normalMapCreatorTool.isComputingNormals = 0; + + references.matProperties[effectPropNormalMap.propertyIndex].textureValue = savedTex; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapEffectDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapEffectDrawer.cs.meta new file mode 100644 index 0000000..8d81621 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapEffectDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 160bf870855ebf849b074fb395bf0e99 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/NormalMapEffectDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/RGBAPackerDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/RGBAPackerDrawer.cs new file mode 100644 index 0000000..a357b90 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/RGBAPackerDrawer.cs @@ -0,0 +1,131 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class RGBAPackerDrawer + { + private const float LABEL_WIDTH = 70f; + private const float TEXTURE_FIELD_WIDTH = 200f; + private const float SPACING_BETWEEN_FIELDS = 20f; + private const float BOOLEAN_LABEL_WIDTH = 100f; + private const float SETTINGS_FIELD_WIDTH = 200f; + + private RGBAPackerTool rgbaPackerTool; + + public RGBAPackerValues ToolValues => rgbaPackerTool.values; + + private CommonStyles commonStyles; + + public RGBAPackerDrawer(RGBAPackerTool rgbaPackerTool, CommonStyles commonStyles) + { + this.rgbaPackerTool = rgbaPackerTool; + this.commonStyles = commonStyles; + } + + public void Draw() + { + GUILayout.Label("RGBA Channel Packer", commonStyles.bigLabel); + GUILayout.Space(20); + GUILayout.Label("Pack red channels from 4 textures into RGBA channels", EditorStyles.boldLabel); + GUILayout.Space(10); + + // Channel texture slots + EditorGUILayout.BeginVertical(); + { + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("R Channel", GUILayout.Width(LABEL_WIDTH)); + ToolValues.rChannelTexture = (Texture2D)EditorGUILayout.ObjectField(ToolValues.rChannelTexture, typeof(Texture2D), false, GUILayout.Width(TEXTURE_FIELD_WIDTH)); + GUILayout.Space(SPACING_BETWEEN_FIELDS); + GUILayout.Label("Default Is White?", GUILayout.Width(BOOLEAN_LABEL_WIDTH)); + ToolValues.rChannelDefaultWhite = EditorGUILayout.Toggle(ToolValues.rChannelDefaultWhite); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("G Channel", GUILayout.Width(LABEL_WIDTH)); + ToolValues.gChannelTexture = (Texture2D)EditorGUILayout.ObjectField(ToolValues.gChannelTexture, typeof(Texture2D), false, GUILayout.Width(TEXTURE_FIELD_WIDTH)); + GUILayout.Space(SPACING_BETWEEN_FIELDS); + GUILayout.Label("Default Is White?", GUILayout.Width(BOOLEAN_LABEL_WIDTH)); + ToolValues.gChannelDefaultWhite = EditorGUILayout.Toggle(ToolValues.gChannelDefaultWhite); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("B Channel", GUILayout.Width(LABEL_WIDTH)); + ToolValues.bChannelTexture = (Texture2D)EditorGUILayout.ObjectField(ToolValues.bChannelTexture, typeof(Texture2D), false, GUILayout.Width(TEXTURE_FIELD_WIDTH)); + GUILayout.Space(SPACING_BETWEEN_FIELDS); + GUILayout.Label("Default Is White?", GUILayout.Width(BOOLEAN_LABEL_WIDTH)); + ToolValues.bChannelDefaultWhite = EditorGUILayout.Toggle(ToolValues.bChannelDefaultWhite); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("A Channel", GUILayout.Width(LABEL_WIDTH)); + ToolValues.aChannelTexture = (Texture2D)EditorGUILayout.ObjectField(ToolValues.aChannelTexture, typeof(Texture2D), false, GUILayout.Width(TEXTURE_FIELD_WIDTH)); + GUILayout.Space(SPACING_BETWEEN_FIELDS); + GUILayout.Label("Default Is White?", GUILayout.Width(BOOLEAN_LABEL_WIDTH)); + ToolValues.aChannelDefaultWhite = EditorGUILayout.Toggle(ToolValues.aChannelDefaultWhite); + } + EditorGUILayout.EndHorizontal(); + } + EditorGUILayout.EndVertical(); + + GUILayout.Space(15); + + // Texture settings + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Texture Size:", GUILayout.MaxWidth(100)); + ToolValues.textureSizes = (TextureSizes)EditorGUILayout.EnumPopup(ToolValues.textureSizes, GUILayout.MaxWidth(SETTINGS_FIELD_WIDTH)); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Filtering:", GUILayout.MaxWidth(100)); + ToolValues.filtering = (FilterMode)EditorGUILayout.EnumPopup(ToolValues.filtering, GUILayout.MaxWidth(SETTINGS_FIELD_WIDTH)); + } + EditorGUILayout.EndHorizontal(); + + GUILayout.Space(10); + + // Info about input channels + int channelCount = 0; + if(ToolValues.rChannelTexture != null) channelCount++; + if(ToolValues.gChannelTexture != null) channelCount++; + if(ToolValues.bChannelTexture != null) channelCount++; + if(ToolValues.aChannelTexture != null) channelCount++; + + int textureSize = (int)ToolValues.textureSizes; + GUILayout.Label($"Output will be a {textureSize}x{textureSize} RGBA texture with {channelCount}/4 channels assigned", EditorStyles.boldLabel); + + if(channelCount == 0) + { + GUILayout.Label("*No input textures assigned - output will use default values", EditorStyles.boldLabel); + } + else if(channelCount < 4) + { + GUILayout.Label($"*{4 - channelCount} channels will use default values (black or white based on toggles)", EditorStyles.boldLabel); + } + + GUILayout.Space(20); + GUILayout.Label("Select the folder where RGBA textures will be saved", EditorStyles.boldLabel); + GlobalConfiguration.instance.AtlasesSavePath = EditorUtils.DrawSelectorFolder(GlobalConfiguration.instance.AtlasesSavePath, "RGBA"); + + if(Directory.Exists(GlobalConfiguration.instance.AtlasesSavePath)) + { + if(GUILayout.Button("Create And Save RGBA Texture", GUILayout.MaxWidth(CommonStyles.BUTTON_WIDTH))) + { + rgbaPackerTool.CreateRGBATexture(); + EditorUtils.SaveTextureAsPNG(GlobalConfiguration.instance.AtlasesSavePath, "RGBA_Packed", "RGBA Channel Packed Texture", ToolValues.createdRGBATexture, ToolValues.filtering, TextureImporterType.Default, TextureWrapMode.Clamp); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/RGBAPackerDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/RGBAPackerDrawer.cs.meta new file mode 100644 index 0000000..05eeac3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/RGBAPackerDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: abdebde6324c8434180274a2f8375efe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/RGBAPackerDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureBlendingEffectDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureBlendingEffectDrawer.cs new file mode 100644 index 0000000..24290c6 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureBlendingEffectDrawer.cs @@ -0,0 +1,168 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class TextureBlendingEffectDrawer : AbstractEffectDrawer + { + private int mainTexPropertyIndex; + private EffectProperty mainNormalEffectProperty; + + private EffectProperty effectPropBlendingSource; + + private EffectProperty effectPropTexBlendingMask; + private EffectProperty effectPropBlendingMaskCutoffG; + private EffectProperty effectPropBlendingMaskSmoothnessG; + private EffectProperty effectPropBlendingMaskCutoffB; + private EffectProperty effectPropBlendingMaskSmoothnessB; + + private EffectProperty effectPropBlendingMaskCutoffWhite; + private EffectProperty effectPropBlendingMaskSmoothnessWhite; + + private EffectProperty effectPropBlendingMode; + + private EffectProperty effectPropBlendingTextureG; + private EffectProperty effectPropBlendingTextureB; + private EffectProperty effectPropBlendingTextureWhite; + + private EffectProperty effectPropBlendingNormalMapG; + private EffectProperty effectPropBlendingNormalMapB; + private EffectProperty effectPropBlendingNormalMapWhite; + + public TextureBlendingEffectDrawer(EffectProperty mainNormalMapEffectProperty, AllIn13DShaderInspectorReferences references, + PropertiesConfig propertiesConfig) : base(references, propertiesConfig) + { + this.drawerID = Constants.TEXTURE_BLENDING_EFFECT_DRAWER_ID; + + mainTexPropertyIndex = FindPropertyIndex("_MainTex"); + this.mainNormalEffectProperty = mainNormalMapEffectProperty; + + this.effectConfig = propertiesConfig.FindEffectConfigByID("TEXTURE_BLENDING"); + + this.effectPropBlendingSource = effectConfig.FindEffectPropertyByName("_TextureBlendingSource"); + + this.effectPropTexBlendingMask = effectConfig.FindEffectPropertyByName("_TexBlendingMask"); + this.effectPropBlendingMaskCutoffG = effectConfig.FindEffectPropertyByName("_BlendingMaskCutoffG"); + this.effectPropBlendingMaskSmoothnessG = effectConfig.FindEffectPropertyByName("_BlendingMaskSmoothnessG"); + this.effectPropBlendingMaskCutoffB = effectConfig.FindEffectPropertyByName("_BlendingMaskCutoffB"); + this.effectPropBlendingMaskSmoothnessB = effectConfig.FindEffectPropertyByName("_BlendingMaskSmoothnessB"); + + this.effectPropBlendingMaskCutoffWhite = effectConfig.FindEffectPropertyByName("_BlendingMaskCutoffWhite"); + this.effectPropBlendingMaskSmoothnessWhite = effectConfig.FindEffectPropertyByName("_BlendingMaskSmoothnessWhite"); + + this.effectPropBlendingMode = effectConfig.FindEffectPropertyByName("_TextureBlendingMode"); + + this.effectPropBlendingTextureG = effectConfig.FindEffectPropertyByName("_BlendingTextureG"); + this.effectPropBlendingTextureB = effectConfig.FindEffectPropertyByName("_BlendingTextureB"); + this.effectPropBlendingTextureWhite = effectConfig.FindEffectPropertyByName("_BlendingTextureWhite"); + + this.effectPropBlendingNormalMapG = effectConfig.FindEffectPropertyByName("_BlendingNormalMapG"); + this.effectPropBlendingNormalMapB = effectConfig.FindEffectPropertyByName("_BlendingNormalMapB"); + this.effectPropBlendingNormalMapWhite = effectConfig.FindEffectPropertyByName("_BlendingNormalMapWhite"); + } + + protected override void DrawProperties() + { + bool isRGBMode = references.IsKeywordEnabled("_TEXTUREBLENDINGMODE_RGB"); + bool isBlendingSourceTexture = references.IsKeywordEnabled("_TEXTUREBLENDINGSOURCE_TEXTURE"); + bool isNormalEnabled = references.IsKeywordEnabled("_NORMAL_MAP_ON"); + + DrawProperty(effectPropBlendingSource); + if(IsEffectPropertyVisible(effectPropTexBlendingMask, references.targetMatInfos)) + { + DrawProperty(effectPropTexBlendingMask); + } + + + DrawProperty(effectPropBlendingMode); + + GUILayout.Space(20f); + + MaterialProperty matPropertyMainNormalMap = references.matProperties[mainNormalEffectProperty.propertyIndex]; + if (isRGBMode) + { + EffectPropertyDrawer.DrawProperty( + materialProperty: references.matProperties[mainTexPropertyIndex], + labelPrefix: string.Empty, + displayName: $"{references.matProperties[mainTexPropertyIndex].displayName} (R)", + customValue: string.Empty, + allowReset: true, + isKeywordProperty: false, + propertyType: EffectProperty.PropertyType.BASIC, + references: references); + + if (isNormalEnabled) + { + EffectPropertyDrawer.DrawProperty( + materialProperty: matPropertyMainNormalMap, + labelPrefix: string.Empty, + displayName: $"{matPropertyMainNormalMap.displayName} (R)", + customValue: string.Empty, + allowReset: true, + isKeywordProperty: false, + propertyType: EffectProperty.PropertyType.BASIC, + references: references); + } + + GUILayout.Space(20f); + + DrawProperty(effectPropBlendingTextureG); + if (isNormalEnabled) + { + DrawProperty(effectPropBlendingNormalMapG); + } + + DrawProperty(effectPropBlendingMaskCutoffG); + DrawProperty(effectPropBlendingMaskSmoothnessG); + GUILayout.Space(20f); + + DrawProperty(effectPropBlendingTextureB); + if (isNormalEnabled) + { + DrawProperty(effectPropBlendingNormalMapB); + } + + DrawProperty(effectPropBlendingMaskCutoffB); + DrawProperty(effectPropBlendingMaskSmoothnessB); + GUILayout.Space(20f); + } + else + { + EffectPropertyDrawer.DrawProperty( + materialProperty: references.matProperties[mainTexPropertyIndex], + labelPrefix: string.Empty, + displayName: $"{references.matProperties[mainTexPropertyIndex].displayName} (Black)", + customValue: string.Empty, + allowReset: true, + isKeywordProperty: false, + propertyType: EffectProperty.PropertyType.BASIC, + references: references); + + if (isNormalEnabled) + { + EffectPropertyDrawer.DrawProperty( + materialProperty: matPropertyMainNormalMap, + labelPrefix: string.Empty, + displayName: $"{matPropertyMainNormalMap.displayName} (R)", + customValue: string.Empty, + allowReset: true, + isKeywordProperty: false, + propertyType: EffectProperty.PropertyType.BASIC, + references: references); + } + + DrawProperty(effectPropBlendingTextureWhite); + if (isNormalEnabled) + { + DrawProperty(effectPropBlendingNormalMapWhite); + } + + if (isBlendingSourceTexture) + { + DrawProperty(effectPropBlendingMaskCutoffWhite); + DrawProperty(effectPropBlendingMaskSmoothnessWhite); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureBlendingEffectDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureBlendingEffectDrawer.cs.meta new file mode 100644 index 0000000..06e9d5a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureBlendingEffectDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 081c5e8bfd291a145abf082e4835e2b2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureBlendingEffectDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureEditorValuesDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureEditorValuesDrawer.cs new file mode 100644 index 0000000..6c058fc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureEditorValuesDrawer.cs @@ -0,0 +1,172 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class TextureEditorValuesDrawer + { + private TextureEditorTool textureEditorTool; + + + private TextureEditorValues values + { + get + { + return textureEditorTool.values; + } + } + + private Texture2D editorTexInput + { + get + { + return textureEditorTool.editorTexInput; + } + } + + private Texture2D editorTex + { + get + { + return textureEditorTool.editorTex; + } + } + + private Texture2D cleanEditorTex + { + get + { + return textureEditorTool.cleanEditorTex; + } + } + + + private const int BUTTON_WIDTH = 600; + + + public void Setup(TextureEditorTool textureEditorTool) + { + this.textureEditorTool = textureEditorTool; + } + + public void Draw() + { + EditorGUILayout.BeginHorizontal(); + + if (!values.showOriginalImage) + { + GUILayout.Label(editorTex); + } + else + { + GUILayout.Label(cleanEditorTex); + } + + EditorGUILayout.BeginVertical(); + + EditorGUI.BeginChangeCheck(); + EditorUtils.TextureEditorColorParameter("Color Tint", ref values.editorColorTint, Color.white); + EditorUtils.TextureEditorFloatParameter("Brightness", ref values.brightness, -1f, 5f); + EditorUtils.TextureEditorFloatParameter("Contrast", ref values.contrast, 0.0f, 5.0f, 1f); + EditorUtils.TextureEditorFloatParameter("Gamma", ref values.gamma, 0.0f, 10f, 1f); + EditorUtils.TextureEditorFloatParameter("Exposure", ref values.exposure, -5f, 5f, 0f); + EditorUtils.TextureEditorFloatParameter("Saturation", ref values.saturation, 0f, 5f, 1f); + EditorUtils.TextureEditorFloatParameter("Hue", ref values.hue, 0f, 360f, 0f); + + EditorGUILayout.BeginHorizontal(); + { + values.invert = EditorGUILayout.Toggle("Invert", values.invert, GUILayout.Width(253)); + values.greyscale = EditorGUILayout.Toggle("Greyscale", values.greyscale); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + values.fullWhite = EditorGUILayout.Toggle("Fully white", values.fullWhite, GUILayout.Width(253)); + values.blackBackground = EditorGUILayout.Toggle("Black background", values.blackBackground); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + values.alphaGreyscale = EditorGUILayout.Toggle("Greyscale is alpha", values.alphaGreyscale, GUILayout.Width(253)); + values.alphaIsOne = EditorGUILayout.Toggle("Alpha to 1", values.alphaIsOne); + } + EditorGUILayout.EndHorizontal(); + + if (EditorGUI.EndChangeCheck()) + { + textureEditorTool.RecalculateEditorTexture(); + } + + EditorGUILayout.Space(); + EditorGUILayout.BeginHorizontal(); + { + if (GUILayout.Button("Rotate Left 90°", GUILayout.MaxWidth(210))) + { + textureEditorTool.RotateEditorTextureLeft(); + } + + if (GUILayout.Button("Rotate Right 90°", GUILayout.MaxWidth(210))) + { + for (int i = 0; i < 3; i++) + { + textureEditorTool.RotateEditorTextureLeft(); + } + } + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + if (GUILayout.Button("Flip Horizontal", GUILayout.MaxWidth(210))) + { + textureEditorTool.FlipEditorTexture(true); + } + + if (GUILayout.Button("Flip Vertical", GUILayout.MaxWidth(210))) + { + textureEditorTool.FlipEditorTexture(false); + } + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Space(); + if (!values.showOriginalImage) + { + if (GUILayout.Button("Press to show Original Image", GUILayout.MaxWidth(425))) + { + values.showOriginalImage = true; + } + } + else + { + Color backgroundColor = GUI.backgroundColor; + GUI.backgroundColor = Color.red; + if (GUILayout.Button("Press to show Editor Image", GUILayout.MaxWidth(425))) + { + values.showOriginalImage = false; + } + GUI.backgroundColor = backgroundColor; + } + + + EditorGUILayout.EndVertical(); + EditorGUILayout.EndHorizontal(); + + GUILayout.Label("*Preview is locked to 256px maximum (bigger textures are scaled down), but the image will be saved to its full resolution", EditorStyles.boldLabel); + + EditorUtils.DrawThinLine(); + EditorGUILayout.Space(); + EditorUtils.TextureEditorFloatParameter("Export Scale", ref values.exportScale, 0.01f, 2f, 1f); + int currWidth = Mathf.ClosestPowerOfTwo((int)(editorTexInput.width * values.exportScale)); + int currHeight = Mathf.ClosestPowerOfTwo((int)(editorTexInput.height * values.exportScale)); + GUILayout.Label("Current export size is: " + currWidth + " x " + currHeight + " (size snaps to the closest power of 2)", EditorStyles.boldLabel); + + if (GUILayout.Button("Save Resulting Image as PNG file", GUILayout.MaxWidth(BUTTON_WIDTH))) + { + textureEditorTool.SaveAsPNG(); + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureEditorValuesDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureEditorValuesDrawer.cs.meta new file mode 100644 index 0000000..5ddcc8d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureEditorValuesDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: d9909526746655a4a9be1aaef56a41b9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/TextureEditorValuesDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/TriplanarEffectDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TriplanarEffectDrawer.cs new file mode 100644 index 0000000..6828f82 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TriplanarEffectDrawer.cs @@ -0,0 +1,63 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class TriplanarEffectDrawer : AbstractEffectDrawer + { + private int mainTexPropertyIndex; + private EffectProperty mainNormalMapProperty; + + public TriplanarEffectDrawer(EffectProperty mainNormalMapProperty, AllIn13DShaderInspectorReferences references, + PropertiesConfig propertiesConfig) : base(references, propertiesConfig) + { + this.drawerID = Constants.TRIPLANAR_EFFECT_DRAWER_ID; + this.mainNormalMapProperty = mainNormalMapProperty; + + mainTexPropertyIndex = FindPropertyIndex("_MainTex"); + } + + protected override void DrawProperties() + { + bool isTriplanarNoiseTransitionEnabled = references.IsKeywordEnabled("_TRIPLANAR_NOISE_TRANSITION_ON"); + + MaterialProperty matProperty = references.matProperties[mainTexPropertyIndex]; + + EffectPropertyDrawer.DrawProperty( + materialProperty: matProperty, + labelPrefix: string.Empty, + displayName: matProperty.displayName, + customValue: string.Empty, + allowReset: true, + isKeywordProperty: false, + propertyType: EffectProperty.PropertyType.BASIC, + references: references); + + EffectProperty triplanarNoiseTransitionToggleProperty = effectConfig.effectProperties[6]; + + DrawProperty(effectConfig.effectProperties[0]); + DrawProperty(effectConfig.effectProperties[1]); + + if (IsEffectPropertyVisible(mainNormalMapProperty, references.targetMatInfos)) + { + EditorUtils.DrawLine(Color.grey, 1, 3); + DrawProperty(mainNormalMapProperty, false); + DrawProperty(effectConfig.effectProperties[2]); + } + + EditorUtils.DrawLine(Color.grey, 1, 3); + DrawProperty(effectConfig.effectProperties[3]); + DrawProperty(effectConfig.effectProperties[4]); + + EditorUtils.DrawLine(Color.grey, 1, 3); + DrawProperty(effectConfig.effectProperties[5]); + DrawProperty(triplanarNoiseTransitionToggleProperty); + + if (isTriplanarNoiseTransitionEnabled) + { + DrawProperty(effectConfig.effectProperties[7]); + DrawProperty(effectConfig.effectProperties[8]); + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/TriplanarEffectDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TriplanarEffectDrawer.cs.meta new file mode 100644 index 0000000..941620e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/TriplanarEffectDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 580ede76f9fd8d844ab570643abe14cd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/TriplanarEffectDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector2Drawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector2Drawer.cs new file mode 100644 index 0000000..240a780 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector2Drawer.cs @@ -0,0 +1,40 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class Vector2Drawer : MaterialPropertyDrawer + { + public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) + { + AllIn1ShaderPropertyType propType = EditorUtils.GetShaderTypeByMaterialProperty(prop); + if (propType != AllIn1ShaderPropertyType.Vector) + { + EditorGUI.LabelField(position, label, "Vector3Drawer only works with Vector properties."); + return; + } + + EditorGUI.BeginChangeCheck(); + + // Get current vector4 value + Vector4 vec4Value = prop.vectorValue; + + // Convert to Vector2 for editing + Vector2 vec2Value = new Vector2(vec4Value.x, vec4Value.y); + + // Create property field for Vector3 + vec2Value = EditorGUI.Vector2Field(position, label, vec2Value); + + if (EditorGUI.EndChangeCheck()) + { + // Convert back to Vector4, preserving the w component + prop.vectorValue = new Vector4(vec2Value.x, vec2Value.y, vec4Value.z, vec4Value.w); + } + } + + public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) + { + return EditorGUIUtility.singleLineHeight; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector2Drawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector2Drawer.cs.meta new file mode 100644 index 0000000..151dc18 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector2Drawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 87a63d9b7f80f9f4bbbe3ae4dc5b0e2a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector2Drawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector3Drawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector3Drawer.cs new file mode 100644 index 0000000..83c72a9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector3Drawer.cs @@ -0,0 +1,38 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class Vector3Drawer : MaterialPropertyDrawer + { + public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) + { + AllIn1ShaderPropertyType propType = EditorUtils.GetShaderTypeByMaterialProperty(prop); + if (propType != AllIn1ShaderPropertyType.Vector) { + EditorGUI.LabelField(position, label, "Vector3Drawer only works with Vector properties."); + return; + } + + EditorGUI.BeginChangeCheck(); + + // Get current vector4 value + Vector4 vec4Value = prop.vectorValue; + + // Convert to Vector3 for editing + Vector3 vec3Value = new Vector3(vec4Value.x, vec4Value.y, vec4Value.z); + + // Create property field for Vector3 + vec3Value = EditorGUI.Vector3Field(position, label, vec3Value); + + if(EditorGUI.EndChangeCheck()) { + // Convert back to Vector4, preserving the w component + prop.vectorValue = new Vector4(vec3Value.x, vec3Value.y, vec3Value.z, vec4Value.w); + } + } + + public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) + { + return EditorGUIUtility.singleLineHeight; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector3Drawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector3Drawer.cs.meta new file mode 100644 index 0000000..2968c44 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector3Drawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: ba6a058864ddc094aa1e321cab78ebd2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Drawers/Vector3Drawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EditorEventManager.cs b/Assets/Plugins/AllIn13DShader/Editor/EditorEventManager.cs new file mode 100644 index 0000000..1cab7ce --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EditorEventManager.cs @@ -0,0 +1,76 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class EditorEventManager : AssetPostprocessor + { + static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload) + { + bool assetImportedForTheFirstTime = IsAssetImportedForTheFirstTime(importedAssets); + if (assetImportedForTheFirstTime) + { + Debug.Log("Setting up AllIn13DShader for the first time..."); + } + +#if ALLIN13DSHADER_URP + URPConfigurator.CheckURPRemoved(deletedAssets, didDomainReload); +#endif + GlobalConfiguration.InitIfNeeded(); + + PropertiesConfigCollection propertiesConfigCollection = PropertiesConfigCreator.InitIfNeeded(importedAssets, deletedAssets, movedAssets, movedFromAssetPaths, didDomainReload); + //GlobalConfiguration.SetPropertiesConfigCollection(propertiesConfigCollection); + GlobalConfiguration.SetupShadersReferences(); + + EffectsProfileCollection effectsProfileCollection = EditorUtils.FindAsset(EffectsProfileCollection.ASSET_NAME); + if (effectsProfileCollection == null) + { + effectsProfileCollection = EffectsProfileCollection.CreateAsset(propertiesConfigCollection); + } + + effectsProfileCollection.BindEffectConfigs(propertiesConfigCollection.propertiesConfig); + + effectsProfileCollection.CleanInvalidProfiles(); + effectsProfileCollection.CheckBakedShadersFolder(propertiesConfigCollection.propertiesConfig); + + for (int i = 0; i < deletedAssets.Length; i++) + { + if (deletedAssets[i].EndsWith(".shader")) + { + effectsProfileCollection.CheckRemovedShader(deletedAssets[i]); + } + } + + if (assetImportedForTheFirstTime) + { + ShaderFeaturesFileCreator.CreateFile(effectsProfileCollection.generalProfile); + } + + GlobalConfiguration.instance.SetEffectsProfileCollection(effectsProfileCollection); + GlobalConfiguration.instance.shaderPassCollection = EditorUtils.FindAsset("ShaderPassCollection"); + + URPSettingsUserPref urpSettingsUserPrefs = URPSettingsUserPref.InitIfNeeded(); + GlobalConfiguration.instance.urpSettingsUserPref = urpSettingsUserPrefs; + +#if ALLIN13DSHADER_URP + URPConfigurator.AllAssetProcessed(); + AllIn13DShaderWindow.AllAssetProcessed(); +#endif + } + + private static bool IsAssetImportedForTheFirstTime(string[] importedAssets) + { + bool res = false; + for(int i = 0; i < importedAssets.Length; i++) + { + if (importedAssets[i].EndsWith(Constants.MAIN_ASSEMBLY_NAME)) + { + res = true; + break; + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EditorEventManager.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EditorEventManager.cs.meta new file mode 100644 index 0000000..058dd41 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EditorEventManager.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: ce9746efb3deeec4f9c874f1dc013239 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EditorEventManager.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectAttributeData.cs b/Assets/Plugins/AllIn13DShader/Editor/EffectAttributeData.cs new file mode 100644 index 0000000..ede6482 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectAttributeData.cs @@ -0,0 +1,25 @@ +namespace AllIn13DShader +{ + public struct EffectAttributeData + { + public string effectID; + public string groupID; + public string drawerID; + public string incompatibleWithEffectID; + public string dependentEffectID; + public bool docEnabled; + + public string[] extraPasses; + + public void Init() + { + this.effectID = string.Empty; + this.groupID = string.Empty; + this.drawerID = string.Empty; + this.incompatibleWithEffectID = string.Empty; + this.dependentEffectID = string.Empty; + this.docEnabled = false; + this.extraPasses = new string[0]; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectAttributeData.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EffectAttributeData.cs.meta new file mode 100644 index 0000000..c3fa8ba --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectAttributeData.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: b36b498226214d04991027c45110f464 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EffectAttributeData.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectConfigType.cs b/Assets/Plugins/AllIn13DShader/Editor/EffectConfigType.cs new file mode 100644 index 0000000..5b04499 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectConfigType.cs @@ -0,0 +1,8 @@ +namespace AllIn13DShader +{ + public enum EffectConfigType + { + EFFECT_TOGGLE = 0, + EFFECT_ENUM = 1, + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectConfigType.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EffectConfigType.cs.meta new file mode 100644 index 0000000..9cdaf94 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectConfigType.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 7dc13376fd758c949b917e33c0e17b0d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EffectConfigType.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectGroup.cs b/Assets/Plugins/AllIn13DShader/Editor/EffectGroup.cs new file mode 100644 index 0000000..db3e0ab --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectGroup.cs @@ -0,0 +1,95 @@ +using System.Collections.Generic; +using UnityEditor; + +namespace AllIn13DShader +{ + [System.Serializable] + public class EffectGroup + { + public EffectGroupGlobalConfig effectGroupConfig; + public AllIn13DEffectConfig[] effects; + + public string GroupID + { + get + { + return effectGroupConfig.groupID; + } + } + + public string DisplayName + { + get + { + return effectGroupConfig.displayName; + } + } + + public EffectGroup(EffectGroupGlobalConfig effectGroupConfig) + { + this.effectGroupConfig = effectGroupConfig; + this.effects = new AllIn13DEffectConfig[0]; + } + + public void AddEffect(AllIn13DEffectConfig effect) + { + ArrayUtility.Add(ref effects, effect); + } + + public AllIn13DEffectConfig FindEffectByID(string effectID) + { + AllIn13DEffectConfig res = null; + + for (int i = 0; i < effects.Length; i++) + { + if (effects[i].effectName == effectID) + { + res = effects[i]; + break; + } + } + + return res; + } + + public List GetEffectPropertyFlatList() + { + List res = new List(); + + for(int i = 0; i < effects.Length; i++) + { + res.AddRange(effects[i].effectProperties); + } + + return res; + } + + public int FindEffectIndexByID(string effectID) + { + int res = -1; + + for(int i = 0; i < effects.Length; i++) + { + if (effects[i].effectName == effectID) + { + res = i; + break; + } + } + + return res; + } + + public string[] GetEffectsNames() + { + string[] res = new string[effects.Length]; + + for(int i = 0; i < effects.Length; i++) + { + res[i] = effects[i].displayName; + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectGroup.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EffectGroup.cs.meta new file mode 100644 index 0000000..f12dee9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectGroup.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: e6e1909f56e3b3540a34f422ffa46b41 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EffectGroup.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfig.cs b/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfig.cs new file mode 100644 index 0000000..4d9169c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfig.cs @@ -0,0 +1,11 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class EffectGroupGlobalConfig : ScriptableObject + { + public string groupID; + public string displayName; + public string libraryFileName; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfig.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfig.cs.meta new file mode 100644 index 0000000..7a0e7ec --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfig.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 6b755efcb87425049878cf9532c736c7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfig.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfigCollection.cs b/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfigCollection.cs new file mode 100644 index 0000000..f4dd9a4 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfigCollection.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class EffectGroupGlobalConfigCollection : ScriptableObject + { + public EffectGroupGlobalConfig[] effectGroupGlobalConfigs; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfigCollection.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfigCollection.cs.meta new file mode 100644 index 0000000..57db2ae --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfigCollection.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 5d4677818a6699f4c951378b8bbde688 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EffectGroupGlobalConfigCollection.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectKeywordData.cs b/Assets/Plugins/AllIn13DShader/Editor/EffectKeywordData.cs new file mode 100644 index 0000000..b2c6359 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectKeywordData.cs @@ -0,0 +1,15 @@ +namespace AllIn13DShader +{ + [System.Serializable] + public struct EffectKeywordData + { + public string keyword; + public string displayName; + + public EffectKeywordData(string keyword, string displayName) + { + this.keyword = keyword; + this.displayName = displayName; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectKeywordData.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EffectKeywordData.cs.meta new file mode 100644 index 0000000..73ac9f6 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectKeywordData.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 545a325a652091c47bffe78f54e5cfea +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EffectKeywordData.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectProfileMaterialInfo.cs b/Assets/Plugins/AllIn13DShader/Editor/EffectProfileMaterialInfo.cs new file mode 100644 index 0000000..de67ecf --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectProfileMaterialInfo.cs @@ -0,0 +1,32 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class EffectProfileMaterialInfo : AbstractMaterialInfo + { + public EffectsProfile effectProfile; + + public EffectProfileMaterialInfo(EffectsProfile effectProfile, Material mat) : base(mat) + { + this.effectProfile = effectProfile; + + RefreshKeywords(); + } + + public override void DisableKeyword(string keyword) + {} + + public override void EnableKeyword(string keyword) + {} + + public override bool IsShaderVariant() + { + return true; + } + + public override void RefreshKeywords() + { + this.enabledKeywords = effectProfile.GetKeywordsEnabled().ToArray(); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectProfileMaterialInfo.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EffectProfileMaterialInfo.cs.meta new file mode 100644 index 0000000..963b8d3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectProfileMaterialInfo.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: b74d701bb8d8c574096fa71cb3d02b0d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EffectProfileMaterialInfo.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectProperty.cs b/Assets/Plugins/AllIn13DShader/Editor/EffectProperty.cs new file mode 100644 index 0000000..05fe020 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectProperty.cs @@ -0,0 +1,151 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + [System.Serializable] + public class EffectProperty + { + public enum PropertyType + { + BASIC = 0, + ENUM = 1, + TOGGLE = 2 + } + + [SerializeReference] public AllIn13DEffectConfig parentEffect; + + public int propertyIndex; + public string propertyName; + public string displayName; + + public List keywords; + public List incompatibleKeywords; + public string[] propertyKeywords; + public string[] fullKeywordNames; + + public KeywordsOp keywordsOp; + public bool allowReset; + + public ShaderPropertyType shaderPropertyType; + + public bool isHDR; + public bool hasTilingAndOffset; + + public EffectProperty(AllIn13DEffectConfig parentEffect, int propertyIndex, string propertyName, string displayName, + KeywordsOp keywordsOp, bool allowReset, ShaderPropertyType shaderPropertyType, ShaderPropertyFlags shaderPropertyFlags) + { + this.parentEffect = parentEffect; + + this.keywords = new List(); + this.incompatibleKeywords = new List(); + this.propertyKeywords = new string[0]; + this.fullKeywordNames = new string[0]; + + this.propertyIndex = propertyIndex; + this.propertyName = propertyName; + this.displayName = displayName; + + this.keywordsOp = keywordsOp; + this.allowReset = allowReset; + + this.shaderPropertyType = shaderPropertyType; + + this.isHDR = shaderPropertyFlags.HasFlag(ShaderPropertyFlags.HDR); + this.hasTilingAndOffset = !shaderPropertyFlags.HasFlag(ShaderPropertyFlags.NoScaleOffset) && shaderPropertyType == ShaderPropertyType.Texture; + } + + public void AddKeyword(string keyword) + { + this.keywords.Add(keyword); + } + + public void AddIncompatibleKeyword(string keyword) + { + this.incompatibleKeywords.Add(keyword); + } + + public void AddPropertyKeywords(List propertyKeywordsToAdd) + { + bool isEnum = propertyKeywordsToAdd.Count > 1; + + for (int i = 0; i < propertyKeywordsToAdd.Count; i++) + { + string fullKeywordName; + if (isEnum) + { + fullKeywordName = this.propertyName.ToUpperInvariant() + "_" + propertyKeywordsToAdd[i].ToUpperInvariant(); + } + else + { + fullKeywordName = propertyKeywordsToAdd[i]; + } + + ArrayUtility.Add(ref this.propertyKeywords, propertyKeywordsToAdd[i]); + ArrayUtility.Add(ref this.fullKeywordNames, fullKeywordName); + } + } + + public bool IsPropertyWithKeywords() + { + bool res = propertyKeywords.Length > 0; + return res; + } + + public bool IsToggleProperty() + { + bool res = propertyKeywords.Length == 1; + return res; + } + + public bool IsEnumProperty() + { + bool res = propertyKeywords.Length >= 2; + return res; + } + + public PropertyType GetPropertyType() + { + PropertyType res = PropertyType.BASIC; + if (IsEnumProperty()) + { + res = PropertyType.ENUM; + } + else if (IsToggleProperty()) + { + res = PropertyType.TOGGLE; + } + + return res; + } + + public int GetEnabledKeywordIndex(string[] enabledKeywords) + { + int res = -1; + + if (IsEnumProperty() || IsToggleProperty()) + { + for (int i = 0; i < enabledKeywords.Length; i++) + { + for (int j = 0; j < fullKeywordNames.Length; j++) + { + if (fullKeywordNames[j] == enabledKeywords[i]) + { + res = j; + break; + } + } + + if (res >= 0) + { + break; + } + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectProperty.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EffectProperty.cs.meta new file mode 100644 index 0000000..3659f71 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectProperty.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 1774734eeb408d648a13a453aae3cdbf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EffectProperty.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectPropertyAttributeData.cs b/Assets/Plugins/AllIn13DShader/Editor/EffectPropertyAttributeData.cs new file mode 100644 index 0000000..6da4177 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectPropertyAttributeData.cs @@ -0,0 +1,49 @@ +using System.Collections.Generic; + +namespace AllIn13DShader +{ + public class EffectPropertyAttributeData + { + public string parentEffectID; + public List keywords; + public List incompatibleWithKws; + public List propertyKeywords; + public List keywordsDisplayNames; + public bool allowReset; + public KeywordsOp keywordsOp; + + public EffectPropertyAttributeData() + { + parentEffectID = string.Empty; + keywords = new List(); + incompatibleWithKws = new List(); + propertyKeywords = new List(); + keywordsDisplayNames = new List(); + allowReset = true; + keywordsOp = KeywordsOp.OR; + } + + public void AddKeyword(string keyword) + { + this.keywords.Add(keyword); + } + + public void AddIncompatibleKeyword(string keyword) + { + this.incompatibleWithKws.Add(keyword); + } + + public void AddPropertyKeyword(string propertyKeyword) + { + this.propertyKeywords.Add(propertyKeyword); + } + + public void AddPropertyKeywords(string[] propertyKeywords) + { + for(int i = 0; i < propertyKeywords.Length; i++) + { + AddPropertyKeyword(propertyKeywords[i].Trim()); + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectPropertyAttributeData.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EffectPropertyAttributeData.cs.meta new file mode 100644 index 0000000..12ca2b7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectPropertyAttributeData.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: b2ec6620d1aff1644a581743ac174c7d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EffectPropertyAttributeData.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles.meta new file mode 100644 index 0000000..531a06a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0bf8c97136cef3f48afc069e94aa3e4a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectProfileCreatorFromShaderVariant.cs b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectProfileCreatorFromShaderVariant.cs new file mode 100644 index 0000000..a52fdc1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectProfileCreatorFromShaderVariant.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using System.IO; +using System.Text.RegularExpressions; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public static class EffectProfileCreatorFromShaderVariant + { + private const string REGEX_EFFECTS_ENABLED_IN_SHADER_VARIANT = @"\/\/((?:\s+#define\s\w+)*\s+)\/\/<\/ALLIN1_EFFECTS>"; + + public static EffectsProfile Create(Shader shaderVariant, string shaderVariantPath, PropertiesConfig propertiesConfig, EffectsProfileCollection effectsProfileCollection) + { + EffectsProfile res = effectsProfileCollection.CreateNewProfile(shaderVariant.name); + res.InitFromOtherProfile(effectsProfileCollection.generalProfile); + + res.shaderGUID = AssetDatabase.AssetPathToGUID(shaderVariantPath); + + string shaderText = File.ReadAllText(shaderVariantPath); + + MatchCollection matchCollection = Regex.Matches(shaderText, REGEX_EFFECTS_ENABLED_IN_SHADER_VARIANT); + + + List enabledKeywordsList = new List(); + if(matchCollection.Count > 0) + { + string matchText = matchCollection[0].Groups[1].Value; + + string[] linesSplitted = matchText.Split("\n"); + + for (int i = 0; i < linesSplitted.Length; i++) + { + string lineProcessed = linesSplitted[i]; + lineProcessed = lineProcessed.Replace("#define", string.Empty); + lineProcessed = lineProcessed.Trim(); + + if (!string.IsNullOrEmpty(lineProcessed)) + { + enabledKeywordsList.Add(lineProcessed); + } + } + } + + string[] enabledKeywordsArray = enabledKeywordsList.ToArray(); + + List allEffects = propertiesConfig.GetAllEffects(); + for(int i = 0; i < allEffects.Count; i++) + { + AllIn13DEffectConfig effect = allEffects[i]; + + if (effect.ContainsSomeKeywordFromList(enabledKeywordsArray)) + { + res.EnableEffect(effect, enabledKeywordsArray); + } + else + { + res.DisableEffect(effect); + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectProfileCreatorFromShaderVariant.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectProfileCreatorFromShaderVariant.cs.meta new file mode 100644 index 0000000..ba79f53 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectProfileCreatorFromShaderVariant.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 6457f0108812aea4291267d576eda7ef +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectProfileCreatorFromShaderVariant.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfile.cs b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfile.cs new file mode 100644 index 0000000..5e5610e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfile.cs @@ -0,0 +1,338 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + [System.Serializable] + public class EffectsProfile + { + public string id; + public string profileName; + + public string shaderGUID; + public List groups; + + public EffectsProfile(string id, string profileName) + { + this.id = id; + + this.profileName = profileName; + FormatProfileName(); + + this.shaderGUID = string.Empty; + this.groups = new List(); + } + + private void FormatProfileName() + { + this.profileName = this.profileName.Replace("\\", "_"); + this.profileName = this.profileName.Replace("/", "_"); + } + + public void InitFromOtherProfile(EffectsProfile copyFrom) + { + this.groups = new List(copyFrom.groups.Count); + for (int i = 0; i < copyFrom.groups.Count; i++) + { + this.groups.Add(new EffectsProfileGroup(copyFrom.groups[i])); + } + } + + public bool IsEffectEnabled(string effectID) + { + EffectsProfileEntry entry = GetEntryByEffectID(effectID); + + bool res = entry.isEnabled; + return res; + } + + public bool IsKeywordEnabled(string effectID, string keyword) + { + EffectsProfileEntry entry = GetEntryByEffectID(effectID); + + bool res = entry.IsKeywordEnabled(keyword); + return res; + } + + public EffectsProfileEntry GetEntryByEffectID(string effectID) + { + EffectsProfileEntry res = null; + + for(int i = 0; i < groups.Count; i++) + { + EffectsProfileGroup group = groups[i]; + for (int j = 0; j < group.entries.Count; j++) + { + if (group.entries[j].effectID == effectID) + { + res = group.entries[j]; + break; + } + } + } + + return res; + } + + public EffectsProfileGroup GetEffectProfileGroupByID(string groupID) + { + EffectsProfileGroup res = null; + + for(int i = 0; i < groups.Count; i++) + { + if (groups[i].effectGroupConfig.groupID == groupID) + { + res = groups[i]; + break; + } + } + + return res; + } + + public void CreateDefault(PropertiesConfigCollection propertiesConfigCollection) + { + groups = new List(); + + PropertiesConfig propertiesConfig = propertiesConfigCollection.FindPropertiesConfigByShader(Shader.Find("AllIn13DShader/AllIn13DShader")); + + for (int i = 0; i < propertiesConfig.effectsGroups.Length; i++) + { + EffectGroup effectGroup = propertiesConfig.effectsGroups[i]; + + EffectsProfileGroup effectsProfileGroup = new EffectsProfileGroup(effectGroup); + groups.Add(effectsProfileGroup); + } + } + + public List GetEnabledEntriesFlatList() + { + List res = new List(); + + for(int i = 0; i < groups.Count; i++) + { + for(int j = 0; j < groups[i].entries.Count; j++) + { + if (groups[i].entries[j].isEnabled) + { + res.Add(groups[i].entries[j]); + } + } + } + + return res; + } + + public List GetShaderPasses(ShaderPassCollection shaderPassCollection, RenderPipelineEnum renderPipeline) + { + List enabledEntries = GetEnabledEntriesFlatList(); + List passesTypeList = new List(); + + List res = new List(); + res.Add(shaderPassCollection.GetShaderPassConfig(AllIn13DPassType.MAIN)); + + for (int i = 0; i < enabledEntries.Count; i++) + { + AllIn13DPassType[] extraPasses = enabledEntries[i].GetExtraPasses(); + for (int j = 0; j < extraPasses.Length; j++) + { + if (extraPasses[j] == AllIn13DPassType.FORWARD_ADD && renderPipeline == RenderPipelineEnum.URP) { continue; } + + ShaderPassConfig shaderPassConfig = shaderPassCollection.GetShaderPassConfig(extraPasses[j]); + if (!res.Contains(shaderPassConfig)) + { + res.Add(shaderPassConfig); + } + } + } + + if (renderPipeline == RenderPipelineEnum.URP) + { + res.Add(shaderPassCollection.GetShaderPassConfig(AllIn13DPassType.DEPTH_NORMALS)); + res.Add(shaderPassCollection.GetShaderPassConfig(AllIn13DPassType.DEPTH_ONLY)); + res.Add(shaderPassCollection.GetShaderPassConfig(AllIn13DPassType.META)); + } + + return res; + } + + public void SetEnableAllEffects(bool enabled) + { + for (int i = 0; i < groups.Count; i++) + { + EffectsProfileGroup group = groups[i]; + for (int j = 0; j < group.entries.Count; j++) + { + EffectsProfileEntry entry = group.entries[j]; + entry.isEnabled = enabled; + } + } + } + + public void EnableAllEffects() + { + SetEnableAllEffects(true); + } + + public void DisableAllEffects() + { + SetEnableAllEffects(false); + } + + public List GetKeywordsEnabled() + { + List res = new List(); + + for(int i = 0; i < groups.Count; i++) + { + EffectsProfileGroup group = groups[i]; + group.CollectKeywords(res); + } + + return res; + } + + public void EnableEffect(AllIn13DEffectConfig effectConfig, string[] enabledKeywords) + { + EffectsProfileEntry effectProfileEntry = GetEntryByEffectID(effectConfig.effectName); + + effectProfileEntry.isEnabled = true; + + if (effectConfig.keywords.Count > 1) + { + int enabledKeywordIndex = -1; + for (int i = 0; i < enabledKeywords.Length; i++) + { + enabledKeywordIndex = effectConfig.GetKeywordIndex(enabledKeywords[i]); + if (enabledKeywordIndex >= 0) + { + break; + } + } + + effectProfileEntry.kwEnabledIndex = enabledKeywordIndex; + } + + for (int i = 0; i < effectConfig.effectProperties.Count; i++) + { + EffectProperty effectProperty = effectConfig.effectProperties[i]; + + if (effectProperty.IsPropertyWithKeywords()) + { + int enabledIndex = 0; + bool isPropertyEnabled = AllIn13DEffectConfig.IsEffectPropertyEnabled(effectProperty, ref enabledIndex, enabledKeywords); + + if (isPropertyEnabled) + { + if (effectProperty.IsEnumProperty()) + { + SubkeywordEntryEnum subkeywordEntryEnum = effectProfileEntry.FindEntryEnumByPropertyName(effectProperty.propertyName); + subkeywordEntryEnum.kwIndexEnabled = effectProperty.GetEnabledKeywordIndex(enabledKeywords); + } + else if (effectProperty.IsToggleProperty()) + { + SubkeywordEntryToggle entryToggle = effectProfileEntry.FindEntryToggleByKeyword(effectProperty.fullKeywordNames[0]); + entryToggle.isEnabled = true; + } + } + else + { + effectProfileEntry.DisableSubEntry(effectProperty); + } + } + } + } + + public void EnableEffect(AllIn13DEffectConfig effectConfig, AbstractMaterialInfo matInfo) + { + EffectsProfileEntry effectProfileEntry = GetEntryByEffectID(effectConfig.effectName); + + effectProfileEntry.isEnabled = true; + + if(effectConfig.keywords.Count > 1) + { + effectProfileEntry.kwEnabledIndex = matInfo.GetEnabledKeywordIndexByEffect(effectConfig); + } + + for(int i = 0; i < effectConfig.effectProperties.Count; i++) + { + EffectProperty effectProperty = effectConfig.effectProperties[i]; + + if (effectProperty.IsPropertyWithKeywords()) + { + int enabledIndex = 0; + bool isPropertyEnabled = AllIn13DEffectConfig.IsEffectPropertyEnabled(effectProperty, ref enabledIndex, matInfo); + + if (isPropertyEnabled) + { + if (effectProperty.IsEnumProperty()) + { + SubkeywordEntryEnum entryEnum = effectProfileEntry.FindEntryEnumByPropertyName(effectProperty.propertyName); + entryEnum.kwIndexEnabled = matInfo.GetEnabledKeywordIndexByEffectProperty(effectProperty); + } + else if (effectProperty.IsToggleProperty()) + { + SubkeywordEntryToggle entryToggle = effectProfileEntry.FindEntryToggleByKeyword(effectProperty.fullKeywordNames[0]); + entryToggle.isEnabled = true; + } + } + else + { + effectProfileEntry.DisableSubEntry(effectProperty); + } + } + } + } + + public Shader FindShader() + { + string shaderPath = AssetDatabase.GUIDToAssetPath(shaderGUID); + Shader res = AssetDatabase.LoadAssetAtPath(shaderPath); + + return res; + } + + public void DisableEffect(AllIn13DEffectConfig effectConfig) + { + EffectsProfileEntry effectProfileEntry = GetEntryByEffectID(effectConfig.effectName); + effectProfileEntry.Disable(); + } + + public void BindEffectConfigs(PropertiesConfig propertiesConfig) + { + for(int i = 0; i < groups.Count; i++) + { + for(int j = 0; j < groups[i].entries.Count; j++) + { + EffectsProfileEntry effectProfileEntry = groups[i].entries[j]; + AllIn13DEffectConfig effectConfig = propertiesConfig.FindEffectConfigByID(effectProfileEntry.effectID); + + effectProfileEntry.BindEffectConfig(effectConfig); + } + } + } + + public List GetEnabledEffectsGroups() + { + List res = new List(); + + for(int i = 0; i < groups.Count; i++) + { + if (groups[i].HasEffectsEnabled()) + { + res.Add(groups[i]); + } + } + + EffectsProfileGroup uvGroup = GetEffectProfileGroupByID(Constants.EFFECT_GROUP_ID_UV_EFFECTS); + EffectsProfileEntry triplanarEntry = GetEntryByEffectID(Constants.EFFECT_ID_TRIPLANAR_MAPPING); + if (triplanarEntry.isEnabled && !uvGroup.HasEffectsEnabled()) + { + res.Add(uvGroup); + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfile.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfile.cs.meta new file mode 100644 index 0000000..0702490 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfile.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 5dab02bb72175f34db48e4348c5a766d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfile.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileCollection.cs b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileCollection.cs new file mode 100644 index 0000000..9eeb6df --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileCollection.cs @@ -0,0 +1,196 @@ +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class EffectsProfileCollection : ScriptableObject + { + public static string ASSET_NAME = "EffectsProfileCollection"; + + public EffectsProfile generalProfile; + public List profiles; + + public static EffectsProfileCollection CreateAsset(PropertiesConfigCollection propertiesConfigCollection) + { + EffectsProfileCollection res = EffectsProfileCollection.CreateInstance(); + + res.profiles = new List(); + + EffectsProfile effectsProfile = new EffectsProfile(string.Empty, string.Empty); + effectsProfile.CreateDefault(propertiesConfigCollection); + res.generalProfile = effectsProfile; + + string path = Path.Combine(GlobalConfiguration.GetDefaultConfigFolderPath(), ASSET_NAME + ".asset"); + AssetDatabase.CreateAsset(res, path); + + return res; + } + + public EffectsProfile FindEffectProfileByGUID(string guid) + { + EffectsProfile res = null; + + for (int i = 0; i < profiles.Count; i++) + { + if (profiles[i].shaderGUID == guid) + { + res = profiles[i]; + break; + } + } + + return res; + } + + public EffectsProfile FindEffectProfileByShader(Shader shader) + { + EffectsProfile res = null; + + string assetPath = AssetDatabase.GetAssetPath(shader); + string guid = AssetDatabase.AssetPathToGUID(assetPath); + + res = FindEffectProfileByGUID(guid); + + return res; + } + + public bool RemoveEffectsProfileByShader(Shader shader) + { + bool res = false; + EffectsProfile effectProfile = FindEffectProfileByShader(shader); + if(effectProfile != null) + { + res = profiles.Remove(effectProfile); + } + + if (res) + { + EditorUtility.SetDirty(this); + } + + return res; + } + + public void ConfigureEffectProfileByMaterialInfo(EffectsProfile target, EffectsProfile activeEffectsList, AbstractMaterialInfo matInfo, PropertiesConfig propertiesConfig) + { + List effectConfigs = propertiesConfig.GetAllEffects(); + for(int i = 0; i < effectConfigs.Count; i++) + { + bool effectEnabled = AllIn13DEffectConfig.IsEffectEnabled(effectConfigs[i], matInfo) && + effectConfigs[i].AreDependenciesMet(propertiesConfig, matInfo) && + activeEffectsList.IsEffectEnabled(effectConfigs[i].effectName); + + if (effectEnabled) + { + target.EnableEffect(effectConfigs[i], matInfo); + } + else + { + target.DisableEffect(effectConfigs[i]); + } + } + } + + public EffectsProfile CreateNewProfile(string profileName) + { + System.Guid guid = System.Guid.NewGuid(); + string id = $"{guid.ToString()}"; + + EffectsProfile res = new EffectsProfile(id, profileName); + + profiles.Add(res); + + return res; + } + + public void BindEffectConfigs(PropertiesConfig propertiesConfig) + { + generalProfile.BindEffectConfigs(propertiesConfig); + + for(int i = 0; i < profiles.Count; i++) + { + profiles[i].BindEffectConfigs(propertiesConfig); + } + } + + public void CleanInvalidProfiles() + { + List profilesToRemove = new List(); + + for (int i = 0; i < profiles.Count - 1; i++) + { + bool removeThisProfile = false; + + if (profiles[i] == null) + { + removeThisProfile = true; + } + else + { + Shader shader = profiles[i].FindShader(); + if(shader == null) + { + removeThisProfile = true; + } + } + + if (removeThisProfile) + { + profilesToRemove.Add(profiles[i]); + } + } + + for(int i = 0; i < profilesToRemove.Count; i++) + { + profiles.Remove(profilesToRemove[i]); + } + } + + public void CheckBakedShadersFolder(string folderPath, PropertiesConfig propertiesConfig) + { + if (AssetDatabase.IsValidFolder(folderPath)) + { + string[] files = Directory.GetFiles(folderPath, "*.shader", SearchOption.AllDirectories); + + for (int i = 0; i < files.Length; i++) + { + Shader shader = (Shader)AssetDatabase.LoadAssetAtPath(files[i], typeof(Shader)); + + EffectsProfile effectProfile = FindEffectProfileByShader(shader); + + if (effectProfile == null) + { + EffectProfileCreatorFromShaderVariant.Create(shader, files[i], propertiesConfig, this); + } + } + } + } + + public void CheckBakedShadersFolder(PropertiesConfig propertiesConfig) + { + string shaderVariantsFolderPath = ShaderVariantCreator.GetShaderVariantsFolderPath(); + CheckBakedShadersFolder(shaderVariantsFolderPath, propertiesConfig); + + if (AssetDatabase.IsValidFolder(Constants.DEMO_SHADERS_BAKED_FOLDER_PATH)) + { + CheckBakedShadersFolder(Constants.DEMO_SHADERS_BAKED_FOLDER_PATH, propertiesConfig); + } + } + + public void CheckRemovedShader(string removedPath) + { + string guid = AssetDatabase.AssetPathToGUID(removedPath); + + EffectsProfile effectsProfileToRemove = FindEffectProfileByGUID(guid); + + if(effectsProfileToRemove != null) + { + profiles.Remove(effectsProfileToRemove); + } + + EditorUtility.SetDirty(this); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileCollection.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileCollection.cs.meta new file mode 100644 index 0000000..b0ce36c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileCollection.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: e9adb408486385f4db34ebf41514603e +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileCollection.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileEntry.cs b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileEntry.cs new file mode 100644 index 0000000..03edaae --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileEntry.cs @@ -0,0 +1,255 @@ +using System.Collections.Generic; +using UnityEditor; + +namespace AllIn13DShader +{ + [System.Serializable] + public class EffectsProfileEntry + { + public string effectID; + public string displayName; + public bool isEnabled; + public int kwEnabledIndex; + + public SubkeywordEntryEnum[] subkeywordEntriesEnum; + public SubkeywordEntryToggle[] subkeywordEntriesToggle; + + private AllIn13DEffectConfig effectConfig; + + public bool IsToggleEffect + { + get + { + bool res = effectConfig.keywords.Count == 1; + return res; + } + } + + public bool IsEnumEffect + { + get + { + bool res = effectConfig.keywords.Count > 1; + return res; + } + } + + public string[] KeywordsDisplayNames + { + get + { + string[] res = effectConfig.keywordsDisplayNames; + return res; + } + } + + public List ParentKeywords + { + get + { + return effectConfig.keywords; + } + } + + public List EffectProperties + { + get + { + return effectConfig.effectProperties; + } + } + + public EffectsProfileEntry(string effectID, string displayName, bool isEnabled) + { + this.effectID = effectID; + this.displayName = displayName; + this.isEnabled = isEnabled; + + subkeywordEntriesEnum = new SubkeywordEntryEnum[0]; + subkeywordEntriesToggle = new SubkeywordEntryToggle[0]; + } + + public EffectsProfileEntry(EffectsProfileEntry copyFrom) + { + this.effectConfig = copyFrom.effectConfig; + + this.effectID = copyFrom.effectID; + this.displayName = copyFrom.displayName; + this.isEnabled = copyFrom.isEnabled; + this.kwEnabledIndex = copyFrom.kwEnabledIndex; + + this.subkeywordEntriesEnum = new SubkeywordEntryEnum[copyFrom.subkeywordEntriesEnum.Length]; + for(int i = 0; i < copyFrom.subkeywordEntriesEnum.Length; i++) + { + this.subkeywordEntriesEnum[i] = new SubkeywordEntryEnum(copyFrom.subkeywordEntriesEnum[i]); + } + + this.subkeywordEntriesToggle = new SubkeywordEntryToggle[copyFrom.subkeywordEntriesToggle.Length]; + for (int i = 0; i < copyFrom.subkeywordEntriesToggle.Length; i++) + { + this.subkeywordEntriesToggle[i] = new SubkeywordEntryToggle(copyFrom.subkeywordEntriesToggle[i]); + } + } + + public void AddSubkeywordEntries(EffectProperty effectProperty) + { + if (effectProperty.IsEnumProperty()) + { + SubkeywordEntryEnum subkeywordEntryEnum = new SubkeywordEntryEnum(0, effectProperty.propertyKeywords, effectProperty.fullKeywordNames, effectProperty.propertyName); + ArrayUtility.Add(ref subkeywordEntriesEnum, subkeywordEntryEnum); + } + else if (effectProperty.IsToggleProperty()) + { + SubkeywordEntryToggle subkeywordEntryToggle = new SubkeywordEntryToggle(false, effectProperty.fullKeywordNames[0], effectProperty.displayName); + ArrayUtility.Add(ref subkeywordEntriesToggle, subkeywordEntryToggle); + } + } + + public bool HasSubkeywords() + { + bool res = subkeywordEntriesEnum.Length != 0 || subkeywordEntriesToggle.Length != 0; + return res; + } + + public void BindEffectConfig(AllIn13DEffectConfig effectConfig) + { + this.effectConfig = effectConfig; + } + + public List GetParentKeywordsEnabled() + { + List res = new List(); + + if (IsToggleEffect) + { + if (isEnabled) + { + res.Add(effectConfig.keywords[0].keyword); + } + } + else if(IsEnumEffect) + { + res.Add(effectConfig.keywords[kwEnabledIndex].keyword); + } + + return res; + } + + public AllIn13DPassType[] GetExtraPasses() + { + return effectConfig.extraPasses; + } + + public bool IsKeywordEnabled(string keyword) + { + bool res = false; + + if (isEnabled) + { + if (IsToggleEffect) + { + res = true; + } + else if (IsEnumEffect) + { + res = effectConfig.keywords[kwEnabledIndex].keyword == keyword; + } + } + return res; + } + + public void CollectKeywords(List res) + { + res.Add(effectConfig.keywords[kwEnabledIndex].keyword); + + for(int i = 0; i < subkeywordEntriesEnum.Length; i++) + { + res.Add(subkeywordEntriesEnum[i].GetKeywordEnabled()); + } + + for(int i = 0; i < subkeywordEntriesToggle.Length; i++) + { + if (subkeywordEntriesToggle[i].isEnabled) + { + res.Add(subkeywordEntriesToggle[i].keyword); + } + } + } + + public int GetDisplayIndex() + { + return effectConfig.displayIndex; + } + + public void Disable() + { + isEnabled = false; + DisableSubEntries(); + } + + public void DisableSubEntries() + { + for(int i = 0; i < subkeywordEntriesEnum.Length; i++) + { + subkeywordEntriesEnum[i].kwIndexEnabled = 0; + } + + for (int i = 0; i < subkeywordEntriesToggle.Length; i++) + { + subkeywordEntriesToggle[i].isEnabled = false; + } + } + + public void DisableSubEntry(EffectProperty effectProperty) + { + if (effectProperty.IsEnumProperty()) + { + SubkeywordEntryEnum entryEnum = FindEntryEnumByPropertyName(effectProperty.propertyName); + if (entryEnum != null) + { + entryEnum.kwIndexEnabled = 0; + } + } + else if (effectProperty.IsToggleProperty()) + { + SubkeywordEntryToggle entryToggle = FindEntryToggleByKeyword(effectProperty.fullKeywordNames[0]); + if (entryToggle != null) + { + entryToggle.isEnabled = false; + } + } + } + + public SubkeywordEntryEnum FindEntryEnumByPropertyName(string propertyName) + { + SubkeywordEntryEnum res = null; + + for(int i = 0; i < subkeywordEntriesEnum.Length; i++) + { + if (subkeywordEntriesEnum[i].propertyName == propertyName) + { + res = subkeywordEntriesEnum[i]; + break; + } + } + + return res; + } + + public SubkeywordEntryToggle FindEntryToggleByKeyword(string keyword) + { + SubkeywordEntryToggle res = null; + + for (int i = 0; i < subkeywordEntriesToggle.Length; i++) + { + if (subkeywordEntriesToggle[i].keyword == keyword) + { + res = subkeywordEntriesToggle[i]; + break; + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileEntry.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileEntry.cs.meta new file mode 100644 index 0000000..76f6708 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileEntry.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 26ed4d8c5c2e86041bc69ba28df977be +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileEntry.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileGroup.cs b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileGroup.cs new file mode 100644 index 0000000..50088d3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileGroup.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; + +namespace AllIn13DShader +{ + [System.Serializable] + public class EffectsProfileGroup + { + public EffectGroupGlobalConfig effectGroupConfig; + public List entries; + + public EffectsProfileGroup(EffectGroup effectGroup) + { + this.effectGroupConfig = effectGroup.effectGroupConfig; + + this.entries = new List(); + + for(int i = 0; i < effectGroup.effects.Length; i++) + { + AllIn13DEffectConfig effectConfig = effectGroup.effects[i]; + EffectsProfileEntry entry = new EffectsProfileEntry(effectConfig.effectName, effectConfig.displayName, true); + + for (int j = 0; j < effectConfig.effectProperties.Count; j++) + { + EffectProperty effectProperty = effectConfig.effectProperties[j]; + + if (effectProperty.IsPropertyWithKeywords()) + { + entry.AddSubkeywordEntries(effectProperty); + } + } + + entries.Add(entry); + } + } + + public EffectsProfileGroup(EffectsProfileGroup copyFrom) + { + this.effectGroupConfig = copyFrom.effectGroupConfig; + this.entries = new List(copyFrom.entries.Count); + for(int i = 0; i < copyFrom.entries.Count; i++) + { + this.entries.Add(new EffectsProfileEntry(copyFrom.entries[i])); + } + } + + public void CollectKeywords(List res) + { + for(int i = 0; i < entries.Count; i++) + { + if (entries[i].isEnabled) + { + entries[i].CollectKeywords(res); + } + } + } + + public bool HasEffectsEnabled() + { + bool res = false; + + for(int i = 0; i < entries.Count; i++) + { + if (entries[i].isEnabled) + { + res = true; + break; + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileGroup.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileGroup.cs.meta new file mode 100644 index 0000000..f5a8a4e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileGroup.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 2a964695b8859f743be3d79f364142ad +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/EffectsProfileGroup.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderFeaturesFileCreator.cs b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderFeaturesFileCreator.cs new file mode 100644 index 0000000..cf334d2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderFeaturesFileCreator.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.IO; +using UnityEditor; + +namespace AllIn13DShader +{ + public static class ShaderFeaturesFileCreator + { + private const string KEYWORD_FOG = "_FOG_ON"; + private const string SHADER_FEATURE_FILE_ENTRY = @"#pragma shader_feature_local {0}"; + private static string TEMPLATE_PATH = GlobalConfiguration.GetRootPluginFolderPath() + "/Editor/Effects Profiles/Templates/ShaderFeaturesTemplate.allin1template"; + private static string DST_PATH = GlobalConfiguration.GetRootPluginFolderPath() + "/Shaders/ShaderLibrary/AllIn13DShader_ShaderFeatures.hlsl"; + + public static void CreateFile(EffectsProfile effectsProfile) + { + string txtGeneratedFile = File.ReadAllText(TEMPLATE_PATH); + string txtContent = string.Empty; + for (int i = 0; i < effectsProfile.groups.Count; i++) + { + EffectsProfileGroup group = effectsProfile.groups[i]; + for (int j = 0; j < group.entries.Count; j++) + { + EffectsProfileEntry effectProfileEntry = group.entries[j]; + if (!effectProfileEntry.isEnabled) { continue; } + + txtContent = ProcessEffectConfig(txtContent, effectProfileEntry); + } + } + + txtContent = AddFogEntry(txtContent); + + txtGeneratedFile = txtGeneratedFile.Replace("", txtContent); + txtGeneratedFile = txtGeneratedFile.Replace("", effectsProfile.id); + + txtGeneratedFile = EditorUtils.UnifyEOL(txtGeneratedFile); + File.WriteAllText(DST_PATH, txtGeneratedFile); + + AssetDatabase.Refresh(); + } + + private static string ProcessEffectConfig(string input, EffectsProfileEntry entry) + { + string res = input; + + List parentKeywords = entry.ParentKeywords; + List effectProperties = entry.EffectProperties; + + for (int i = 0; i < parentKeywords.Count; i++) + { + string fileEntry = string.Format(SHADER_FEATURE_FILE_ENTRY, parentKeywords[i].keyword); + res += fileEntry; + res += "\n"; + } + + for (int i = 0; i < effectProperties.Count; i++) + { + EffectProperty effectProperty = effectProperties[i]; + + for (int j = 0; j < effectProperty.propertyKeywords.Length; j++) + { + if (effectProperty.IsEnumProperty()) + { + res += string.Format(SHADER_FEATURE_FILE_ENTRY, effectProperty.fullKeywordNames[j]); + } + else + { + res += string.Format(SHADER_FEATURE_FILE_ENTRY, effectProperty.propertyKeywords[j]); + } + + res += "\n"; + } + } + + return res; + } + + private static string AddFogEntry(string fileContent) + { + string res = fileContent; + + res += string.Format(SHADER_FEATURE_FILE_ENTRY, KEYWORD_FOG); + res += "\n"; + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderFeaturesFileCreator.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderFeaturesFileCreator.cs.meta new file mode 100644 index 0000000..4561cfd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderFeaturesFileCreator.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 5fe0720354f0da947a8fd419d3d70fc5 +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderFeaturesFileCreator.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderVariantCreator.cs b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderVariantCreator.cs new file mode 100644 index 0000000..59fe2fb --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderVariantCreator.cs @@ -0,0 +1,265 @@ +using System; +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public static class ShaderVariantCreator + { + private const string INCLUDE_LINE_FORMAT = @"#include ""{0}"""; + + private const string TAG_VARIANT_NAME = @""; + private const string TAG_SHADER_PROPERTIES = @""; + + private const string TAG_SHADER_PASSES_URP = @""; + private const string TAG_SHADER_PASSES_BIRP = @""; + + // + private const string TAG_PASS_NAME = @""; + private const string TAG_LIGHT_MODE = @""; + private const string TAG_BLEND_COMMAND = @""; + private const string TAG_CULL_COMMAND = @""; + + + private const string TAG_Z_WRITE_COMMAND = @""; + + private const string TAG_Z_TEST_COMMAND = @""; + + private const string TAG_COLOR_MASK_COMMAND = @""; + + + private const string TAG_STENCIL_BLOCK = @""; + private const string TAG_FEATURES_URP_DEFINES = @""; + private const string TAG_FEATURES_URP_LIBRARY = @""; + private const string TAG_VERTEX_PROGRAM_NAME = @""; + private const string TAG_FRAGMENT_PROGRAM_NAME = @""; + private const string TAG_ALL_IN_1_FEATURES = @""; + private const string TAG_PIPELINE_PASS_SYMBOL = @""; + private const string TAG_THIS_PASS_SYMBOL = @""; + private const string TAG_INCLUDE_PIPELINE_HELPER = @""; + private const string TAG_INCLUDE_EFFECT_LIBRARIES = @""; + private const string TAG_INCLUDE_PASS = @""; + private const string TAG_EXTRA_PRAGMA_LINES = @""; + + private const string TAG_INCLUDE_ALL_IN_SHADER_FEATURES = @""; + private const string TAG_INCLUDE_ALL_IN_1_SHADER_LIGHT = @""; + private const string TAG_INCLUDE_CORE_LIBRARY = @""; + private const string TAG_INCLUDE_COMMON_FUNCTIONS = @""; + private const string TAG_INCLUDE_COMMON_STRUCTS = @""; + // + + private static string TEMPLATE_PATH = GlobalConfiguration.GetRootPluginFolderPath() + "/Editor/Effects Profiles/Templates/ShaderTemplate.allin1template"; + private static string SHADER_PROPERTIES_PATH = GlobalConfiguration.GetRootPluginFolderPath() + "/Editor/Templates/AllIn13DShader_ShaderProperties.allIn13DData"; + private static string SHADER_PASS_URP_TAMPLATE_PATH = GlobalConfiguration.GetRootPluginFolderPath() + "/Editor/Effects Profiles/Templates/PassTemplate_URP.allin1template"; + private static string SHADER_PASS_BIRP_TAMPLATE_PATH = GlobalConfiguration.GetRootPluginFolderPath() + "/Editor/Effects Profiles/Templates/PassTemplate_BIRP.allin1template"; + + + public static string SHADER_VARIANTS_FOLDER_NAME = "Baked Variants"; + private static string SHADER_VARIANT_FILE_NAME = "AllIn13D_BakedEffects_{0}.shader"; + + public static Shader CreateVariantByMaterialInfo(PropertiesConfig propertiesConfig, AbstractMaterialInfo matInfo, string profileName) + { + EffectsProfileCollection effectsProfileCollection = GlobalConfiguration.instance.effectsProfileCollection; + + EffectsProfile effectsProfile = effectsProfileCollection.CreateNewProfile(profileName); + + effectsProfile.InitFromOtherProfile(effectsProfileCollection.generalProfile); + effectsProfileCollection.ConfigureEffectProfileByMaterialInfo( + target: effectsProfile, + activeEffectsList: effectsProfileCollection.generalProfile, + matInfo: matInfo, + propertiesConfig: propertiesConfig); + + string folderPath = GlobalConfiguration.instance.BakedShaderSavePath; + Shader res = CreateVariant(effectsProfile, effectsProfileCollection, folderPath, false); + + return res; + } + + public static Shader CreateVariant(EffectsProfileCollection effectsProfileCollection, string profileName) + { + EffectsProfile effectProfile = effectsProfileCollection.CreateNewProfile(profileName); + effectProfile.InitFromOtherProfile(effectsProfileCollection.generalProfile); + + string folderPath = GlobalConfiguration.instance.BakedShaderSavePath; + Shader res = CreateVariant(effectProfile, effectsProfileCollection, folderPath, false); + return res; + } + + public static Shader CreateVariant(EffectsProfile effectsProfile, EffectsProfileCollection effectsProfileCollection, string folderPath, bool overwrite) + { + string txtShaderVariant = File.ReadAllText(TEMPLATE_PATH); + + txtShaderVariant = ConfigureVariantName(txtShaderVariant, effectsProfile.profileName); + txtShaderVariant = ConfigureShaderProperties(txtShaderVariant); + + ShaderPassCollection shaderPassCollection = GlobalConfiguration.instance.shaderPassCollection; + + string urpPassesEntry = GetShaderPassesEntry(effectsProfile, shaderPassCollection, RenderPipelineEnum.URP, folderPath); + txtShaderVariant = txtShaderVariant.Replace(TAG_SHADER_PASSES_URP, urpPassesEntry); + + string birpPassesEntry = GetShaderPassesEntry(effectsProfile, shaderPassCollection, RenderPipelineEnum.BIRP, folderPath); + txtShaderVariant = txtShaderVariant.Replace(TAG_SHADER_PASSES_BIRP, birpPassesEntry); + + + string filePath; + if (overwrite) + { + Shader shader = effectsProfile.FindShader(); + filePath = AssetDatabase.GetAssetPath(shader); + } + else + { + string fileName = string.Format(SHADER_VARIANT_FILE_NAME, effectsProfile.profileName); + filePath = Path.Combine(folderPath, fileName); + + filePath = AssetDatabase.GenerateUniqueAssetPath(filePath); + } + + effectsProfile.shaderGUID = AssetDatabase.AssetPathToGUID(filePath); + + + txtShaderVariant = EditorUtils.UnifyEOL(txtShaderVariant); + SaveFile(filePath, txtShaderVariant); + AssetDatabase.Refresh(); + + Shader res = AssetDatabase.LoadAssetAtPath(filePath, typeof(Shader)) as Shader; + EditorUtility.SetDirty(effectsProfileCollection); + + return res; + } + + private static void SaveFile(string filePath, string txtFile) + { + File.WriteAllText(filePath, txtFile); + } + + private static string ConfigureVariantName(string input, string variantName) + { + string res = input.Replace(TAG_VARIANT_NAME, variantName); + return res; + } + + private static string ConfigureShaderProperties(string input) + { + string res = input; + + string shaderPropertiesTxt = EditorUtils.ReadFileTextWithTabs(SHADER_PROPERTIES_PATH, 2); + res = res.Replace(TAG_SHADER_PROPERTIES, shaderPropertiesTxt); + + return res; + } + + private static string GetShaderPassesEntry(EffectsProfile effectsProfile, ShaderPassCollection shaderPassCollection, RenderPipelineEnum renderPipeline, string shaderFolderPath) + { + string shaderPassTemplateTxt = EditorUtils.ReadFileTextWithTabs(GetTemplatePathByRenderPipeline(renderPipeline), 2); + + List shaderPasses = effectsProfile.GetShaderPasses(shaderPassCollection, renderPipeline); + + bool hasStencilBlock = false; + for(int i = 0; i < shaderPasses.Count; i++) + { + if (shaderPasses[i].passType == AllIn13DPassType.OUTLINE) + { + hasStencilBlock = true; + break; + } + } + + string res = string.Empty; + for (int i = 0; i < shaderPasses.Count; i++) + { + string currentPass = shaderPassTemplateTxt; + currentPass = ConfigureShaderPass(effectsProfile, currentPass, shaderPasses[i], renderPipeline, hasStencilBlock, shaderFolderPath); + + res += currentPass; + res += "\n"; + } + + return res; + } + + private static string ConfigureShaderPass(EffectsProfile effectsProfile, + string templatePass, ShaderPassConfig shaderPass, RenderPipelineEnum renderPipeline, bool hasStencilBlock, + string shaderFolderPath) + { + string res = templatePass; + + res = res.Replace(TAG_PASS_NAME, shaderPass.GetPassName(renderPipeline)); + + res = res.Replace(TAG_LIGHT_MODE, shaderPass.GetLightModeShaderEntry(renderPipeline)); + + res = res.Replace(TAG_BLEND_COMMAND, shaderPass.blendCommand.GetShaderEntry()); + + res = res.Replace(TAG_CULL_COMMAND, shaderPass.cullCommand.GetShaderEntry()); + res = res.Replace(TAG_Z_WRITE_COMMAND, shaderPass.zWriteCommand.GetShaderEntry()); + res = res.Replace(TAG_Z_TEST_COMMAND, shaderPass.zTestCommand.GetShaderEntry()); + res = res.Replace(TAG_COLOR_MASK_COMMAND, shaderPass.colorMaskCommand.GetShaderEntry()); + + if (hasStencilBlock) + { + res = res.Replace(TAG_STENCIL_BLOCK, shaderPass.GetStencilBlockShaderEntry(effectsProfile)); + } + else + { + res = res.Replace(TAG_STENCIL_BLOCK, string.Empty); + } + + res = res.Replace(TAG_FEATURES_URP_DEFINES, shaderPass.GetPipelineFeaturesDefinesShaderEntry(renderPipeline, shaderFolderPath)); + res = res.Replace(TAG_FEATURES_URP_LIBRARY, shaderPass.GetPipelineFeaturesLibraryShaderEntry(renderPipeline, shaderFolderPath)); + + res = res.Replace(TAG_VERTEX_PROGRAM_NAME, shaderPass.vertexProgramName); + res = res.Replace(TAG_FRAGMENT_PROGRAM_NAME, shaderPass.fragmentProgramName); + + res = res.Replace(TAG_INCLUDE_PIPELINE_HELPER, string.Format(INCLUDE_LINE_FORMAT, shaderPass.GetHelperLibraryPath(renderPipeline, shaderFolderPath))); + + string effectsLibraries = shaderPass.GetEffectsLibrariesShaderEntry(effectsProfile, shaderFolderPath); + res = res.Replace(TAG_INCLUDE_EFFECT_LIBRARIES, effectsLibraries); + + res = res.Replace(TAG_INCLUDE_PASS, string.Format(INCLUDE_LINE_FORMAT, shaderPass.GetPassFilePath(shaderFolderPath))); + + List enabledEntries = effectsProfile.GetEnabledEntriesFlatList(); + string entryFeaturesTxt = ShaderPassConfig.GetAllIn1FeaturesEntries(enabledEntries); + + res = res.Replace(TAG_ALL_IN_1_FEATURES, entryFeaturesTxt); + + res = res.Replace(TAG_PIPELINE_PASS_SYMBOL, shaderPass.GetPipelinePassSymbolShaderEntry(renderPipeline)); + res = res.Replace(TAG_THIS_PASS_SYMBOL, shaderPass.GetPassSymbolShaderEntry()); + + res = res.Replace(TAG_EXTRA_PRAGMA_LINES, shaderPass.GetExtraPragmaLines(renderPipeline)); + + res = res.Replace(TAG_INCLUDE_ALL_IN_SHADER_FEATURES, shaderPass.GetShaderFeaturesLibraryShaderEntry(shaderFolderPath)); + res = res.Replace(TAG_INCLUDE_ALL_IN_1_SHADER_LIGHT, shaderPass.GetLightLibraryShaderEntry(shaderFolderPath)); + res = res.Replace(TAG_INCLUDE_CORE_LIBRARY, shaderPass.GetCoreLibraryShaderEntry(shaderFolderPath)); + res = res.Replace(TAG_INCLUDE_COMMON_STRUCTS, shaderPass.GetCommonStructsShaderEntry(shaderFolderPath)); + res = res.Replace(TAG_INCLUDE_COMMON_FUNCTIONS, shaderPass.GetCommonFunctionsShaderEntry(shaderFolderPath)); + + return res; + } + + private static string GetTemplatePathByRenderPipeline(RenderPipelineEnum renderPipeline) + { + string res = string.Empty; + switch (renderPipeline) + { + case RenderPipelineEnum.BIRP: + res = SHADER_PASS_BIRP_TAMPLATE_PATH; + break; + + case RenderPipelineEnum.URP: + res = SHADER_PASS_URP_TAMPLATE_PATH; + break; + } + + return res; + } + + public static string GetShaderVariantsFolderPath() + { + string res = GlobalConfiguration.instance.BakedShaderSavePath; + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderVariantCreator.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderVariantCreator.cs.meta new file mode 100644 index 0000000..f14329f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderVariantCreator.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: cfa22d77b9798ec4e85780c7027525aa +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/ShaderVariantCreator.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryEnum.cs b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryEnum.cs new file mode 100644 index 0000000..aafa6c1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryEnum.cs @@ -0,0 +1,51 @@ +namespace AllIn13DShader +{ + [System.Serializable] + public class SubkeywordEntryEnum + { + public string propertyName; + + public int kwIndexEnabled; + public string[] displayNames; + public string[] keywords; + + public SubkeywordEntryEnum(int kwIndexEnabled, string[] displayNames, string[] keywords, string propertyName) + { + this.propertyName = propertyName; + + this.displayNames = new string[displayNames.Length]; + this.keywords = new string[keywords.Length]; + + for (int i = 0; i < displayNames.Length; i++) + { + this.displayNames[i] = displayNames[i]; + this.keywords[i] = keywords[i]; + } + } + + public SubkeywordEntryEnum(SubkeywordEntryEnum copyFrom) + { + this.kwIndexEnabled = copyFrom.kwIndexEnabled; + + this.displayNames = new string[copyFrom.displayNames.Length]; + for(int i = 0; i < copyFrom.displayNames.Length; i++) + { + this.displayNames[i] = copyFrom.displayNames[i]; + } + + this.keywords = new string[copyFrom.keywords.Length]; + for(int i = 0; i < copyFrom.keywords.Length; i++) + { + this.keywords[i] = copyFrom.keywords[i]; + } + + this.propertyName = copyFrom.propertyName; + } + + public string GetKeywordEnabled() + { + string res = keywords[kwIndexEnabled]; + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryEnum.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryEnum.cs.meta new file mode 100644 index 0000000..4d66502 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryEnum.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: db7fa625c91a86a4bad1196d616642bf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryEnum.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryToggle.cs b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryToggle.cs new file mode 100644 index 0000000..d49244c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryToggle.cs @@ -0,0 +1,26 @@ +namespace AllIn13DShader +{ + [System.Serializable] + public class SubkeywordEntryToggle + { + public string propertyName; + + public bool isEnabled; + public string keyword; + public string displayName; + + public SubkeywordEntryToggle(bool isEnabled, string keyword, string displayName) + { + this.isEnabled = isEnabled; + this.keyword = keyword; + this.displayName = displayName; + } + + public SubkeywordEntryToggle(SubkeywordEntryToggle copyFrom) + { + this.isEnabled = copyFrom.isEnabled; + this.keyword = copyFrom.keyword; + this.displayName = copyFrom.displayName; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryToggle.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryToggle.cs.meta new file mode 100644 index 0000000..9c24d60 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryToggle.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 1e0090a98f8b7814693852d420e4822e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/SubkeywordEntryToggle.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates.meta new file mode 100644 index 0000000..21c61df --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fc0645fb7502dce48abc80e20c4acaa1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_BIRP.allin1template b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_BIRP.allin1template new file mode 100644 index 0000000..190baad --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_BIRP.allin1template @@ -0,0 +1,46 @@ +Pass +{ + Name "" + Tags + { + + } + + + + + + + + + + HLSLPROGRAM + #pragma target 3.0 + + #pragma vertex + #pragma fragment + + + + #define ALLIN1_SHADER_VARIANT + + + + // + + // + + #include "UnityCG.cginc" + + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + + + + + + + + + ENDHLSL +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_BIRP.allin1template.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_BIRP.allin1template.meta new file mode 100644 index 0000000..444810e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_BIRP.allin1template.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 0b7fd35e09faa604e81cdb0b41a5ced4 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_BIRP.allin1template + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_URP.allin1template b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_URP.allin1template new file mode 100644 index 0000000..f68f268 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_URP.allin1template @@ -0,0 +1,52 @@ +Pass +{ + Name "" + Tags + { + + } + + + + + + + + + + HLSLPROGRAM + #pragma vertex + #pragma fragment + + #define ALLIN1_SHADER_VARIANT + + + + + + + #ifdef ALLIN1_DOTS_INSTANCING_SUPPORT + #pragma target 4.5 + #else + #pragma target 3.0 + #endif + + // + + // + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + + + + + + + + + + ENDHLSL +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_URP.allin1template.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_URP.allin1template.meta new file mode 100644 index 0000000..e9cfea4 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_URP.allin1template.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 82e31d9f58451684ab6f3ac5a299f971 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/PassTemplate_URP.allin1template + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderFeaturesTemplate.allin1template b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderFeaturesTemplate.allin1template new file mode 100644 index 0000000..ab1ab9f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderFeaturesTemplate.allin1template @@ -0,0 +1,6 @@ +#ifndef ALLIN13DSHADER_SHADERFEATURES_ +#define ALLIN13DSHADER_SHADERFEATURES_ + + + +#endif //ALLIN13DSHADER_SHADERFEATURES_ \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderFeaturesTemplate.allin1template.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderFeaturesTemplate.allin1template.meta new file mode 100644 index 0000000..f951de0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderFeaturesTemplate.allin1template.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 2c7e49c3cff475d47a9837ad32530a72 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderFeaturesTemplate.allin1template + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderTemplate.allin1template b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderTemplate.allin1template new file mode 100644 index 0000000..1576900 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderTemplate.allin1template @@ -0,0 +1,24 @@ +Shader "AllIn13DShader - Baked Effects/" +{ + Properties + { + + } + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "12.0" + } + + + } + + SubShader + { + + } + + CustomEditor "AllIn13DShader.AllIn13DShaderMaterialInspector" +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderTemplate.allin1template.meta b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderTemplate.allin1template.meta new file mode 100644 index 0000000..6cd498e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderTemplate.allin1template.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 1008b6c26c1d5604fbea18f1f31eb1bd +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Effects Profiles/Templates/ShaderTemplate.allin1template + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectsExtraData.cs b/Assets/Plugins/AllIn13DShader/Editor/EffectsExtraData.cs new file mode 100644 index 0000000..442476a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectsExtraData.cs @@ -0,0 +1,63 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class EffectsExtraData : ScriptableObject + { + [System.Serializable] + public class ExtraData + { + public string effectID; + public string docURL; + public MessageByKeywords[] customMessages; + } + + [System.Serializable] + public class MessageByKeywords + { + [TextArea]public string message; + public string[] keywords; + + public bool IsMessageEnabled(AbstractMaterialInfo targetMatInfo) + { + bool res = false; + + if (keywords.Length == 0) + { + res = true; + } + else + { + for (int i = 0; i < keywords.Length; i++) + { + if (targetMatInfo.IsKeywordEnabled(keywords[i])) + { + res = true; + break; + } + } + } + + return res; + } + } + + public ExtraData[] effectsExtraData; + + public ExtraData GetExtraDataByEffectID(string effectID) + { + ExtraData res = null; + + for(int i = 0; i < effectsExtraData.Length; i++) + { + if (effectsExtraData[i].effectID == effectID) + { + res = effectsExtraData[i]; + break; + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/EffectsExtraData.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/EffectsExtraData.cs.meta new file mode 100644 index 0000000..58dcbcb --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/EffectsExtraData.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 32438765f2955064bae29bed18ec5263 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/EffectsExtraData.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Gizmos.meta b/Assets/Plugins/AllIn13DShader/Editor/Gizmos.meta new file mode 100644 index 0000000..bcff7d3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Gizmos.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6312b0fe2404db74f9cf28c574209caf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Gizmos/Fast_Light_Icon.png b/Assets/Plugins/AllIn13DShader/Editor/Gizmos/Fast_Light_Icon.png new file mode 100644 index 0000000..331343d Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Editor/Gizmos/Fast_Light_Icon.png differ diff --git a/Assets/Plugins/AllIn13DShader/Editor/Gizmos/Fast_Light_Icon.png.meta b/Assets/Plugins/AllIn13DShader/Editor/Gizmos/Fast_Light_Icon.png.meta new file mode 100644 index 0000000..7b1133e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Gizmos/Fast_Light_Icon.png.meta @@ -0,0 +1,118 @@ +fileFormatVersion: 2 +guid: 09c6972b347513048a553660289f5d9d +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Gizmos/Fast_Light_Icon.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Gizmos/GizmoIcon_Wind.png b/Assets/Plugins/AllIn13DShader/Editor/Gizmos/GizmoIcon_Wind.png new file mode 100644 index 0000000..cf0f5a9 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Editor/Gizmos/GizmoIcon_Wind.png differ diff --git a/Assets/Plugins/AllIn13DShader/Editor/Gizmos/GizmoIcon_Wind.png.meta b/Assets/Plugins/AllIn13DShader/Editor/Gizmos/GizmoIcon_Wind.png.meta new file mode 100644 index 0000000..06ab12f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Gizmos/GizmoIcon_Wind.png.meta @@ -0,0 +1,118 @@ +fileFormatVersion: 2 +guid: 6e5669f91329b474b9a081e479853f82 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Gizmos/GizmoIcon_Wind.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/GlobalConfiguration.cs b/Assets/Plugins/AllIn13DShader/Editor/GlobalConfiguration.cs new file mode 100644 index 0000000..ce76ede --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/GlobalConfiguration.cs @@ -0,0 +1,630 @@ +using System.IO; +using UnityEditor; +using UnityEditorInternal; +using UnityEngine; + +namespace AllIn13DShader +{ + public class GlobalConfiguration : ScriptableObject + { + private static GlobalConfiguration _instance; + public static GlobalConfiguration instance + { + get + { + return _instance; + } + } + + + public enum ProjectType + { + [InspectorName("Standard PBR")]STANDARD_PBR = 2, + [InspectorName("Standard Basic")]STANDARD_BASIC = 1, + [InspectorName("AllIn13DShader Look")] ALLIN13DSHADERLOOK = 4, + [InspectorName("Toon")] TOON = 0, + [InspectorName("Custom")] CUSTOM = 3, + } + + //Project type and default materials + public ProjectType projectType; + + public Material standardBasicMaterial; + public Material standardPBRMaterial; + public Material toonMaterial; + public Material allIn13dDShaderLookMaterial; + + public Material defaultPreset; + + + // + public const string MAIN_ASSEMBLY_NAME = "AllIn13DShaderAssembly"; + + // + public const string ALLIN13SHADER_CONFIG_DEFAULT_FOLDER_NAME = "AllIn3DShaderConfig"; + //public const string ALLIN13SHADER_CONFIG_DEFAULT_FOLDER = "Assets/AllIn3DShaderConfig"; + public const string GLOBAL_CONFIGURATION_ASSET_NAME = "GlobalConfiguration.asset"; + + //Default Relative Paths + + public const string MATERIAL_SAVE_FOLDER_NAME = "Materials"; + public const string RENDER_IMAGE_SAVE_FOLDER_NAME = "Images"; + public const string NORMAL_MAP_SAVE_FOLDER_NAME = "Normal Maps"; + public const string GRADIENT_SAVE_FOLDER_NAME = "Gradients"; + public const string ATLASES_SAVE_FOLDER_NAME = "Atlases"; + public const string NOISES_SAVE_FOLDER_NAME = "Noises"; + public const string BAKED_SHADER_FOLDER_NAME = "Baked Shaders"; + + //Default Root Plugin Path + public const string GLOBAL_CONFIG_FOLDER_DEFAULT_PATH = "AllIn3DShaderConfig"; + public const string EXPORT_FOLDER_NAME_DEFAULT = "Export"; + + //Paths + [SerializeField] private string rootPluginPath; + [SerializeField] private string globalConfigFolderPath; + [SerializeField] private string exportFolderPath; + [SerializeField] private string materialSavePath; + [SerializeField] private string renderImageSavePath; + [SerializeField] private string normalMapSavePath; + [SerializeField] private string gradientSavePath; + [SerializeField] private string atlasesSavePath; + [SerializeField] private string noiseSavePath; + [SerializeField] private string bakedShaderSavePath; + + //Render Image Scale + [SerializeField] private float renderImageScale; + + //Project configured first time + [SerializeField] private bool projectConfiguredFirstTime; + + //URP Configured first time + [SerializeField] private bool urpConfiguredFirstTime; + [SerializeField] private string lastPipelineConfiguredGUID; + + //Properties Config Collection + //public PropertiesConfigCollection propertiesConfigCollection; + + //Shaders + public Shader shStandard; + public Shader shStandardNoShadowCaster; + public Shader shOutline; + public Shader shOutlineNoShadowCaster; + + //Effects Profile + public EffectsProfileCollection effectsProfileCollection; + + //Shader Pass Collection + public ShaderPassCollection shaderPassCollection; + + //URP Settings User Preferences + public URPSettingsUserPref urpSettingsUserPref; + + public string RootPluginPath + { + get + { + return rootPluginPath; + } + set + { + rootPluginPath = value; + EditorUtility.SetDirty(this); + } + } + + public string GlobalConfigFolderPath + { + get + { + return globalConfigFolderPath; + } + set + { + globalConfigFolderPath = value; + EditorUtility.SetDirty(this); + } + } + + public string ExportFolderPath + { + get + { + return exportFolderPath; + } + set + { + exportFolderPath = value; + EditorUtility.SetDirty(this); + } + } + + public string MaterialSavePath + { + get + { + return materialSavePath; + } + set + { + materialSavePath = value; + EditorUtility.SetDirty(this); + } + } + + public string RenderImageSavePath + { + get + { + return renderImageSavePath; + } + set + { + renderImageSavePath = value; + EditorUtility.SetDirty(this); + } + } + + public string NormalMapSavePath + { + get + { + return normalMapSavePath; + } + set + { + normalMapSavePath = value; + EditorUtility.SetDirty(this); + } + } + + public string GradientSavePath + { + get + { + return gradientSavePath; + } + set + { + gradientSavePath = value; + EditorUtility.SetDirty(this); + } + } + + public string AtlasesSavePath + { + get + { + return atlasesSavePath; + } + set + { + atlasesSavePath = value; + EditorUtility.SetDirty(this); + } + } + + public string NoiseSavePath + { + get + { + return noiseSavePath; + } + set + { + noiseSavePath = value; + EditorUtility.SetDirty(this); + } + } + + public string BakedShaderSavePath + { + get + { + return bakedShaderSavePath; + } + set + { + bakedShaderSavePath = value; + EditorUtility.SetDirty(this); + } + } + + public string GradientsSavePath + { + get + { + return gradientSavePath; + } + set + { + gradientSavePath = value; + EditorUtility.SetDirty(this); + } + } + + public float RenderImageScale + { + get + { + return renderImageScale; + } + set + { + renderImageScale = value; + EditorUtility.SetDirty(this); + } + } + + public bool ProjectConfiguredFirstTime + { + get + { + return projectConfiguredFirstTime; + } + set + { + projectConfiguredFirstTime = value; + EditorUtility.SetDirty(this); + } + } + + public bool URPConfiguredFirstTime + { + get + { + return urpConfiguredFirstTime; + } + set + { + urpConfiguredFirstTime = value; + EditorUtility.SetDirty(this); + } + } + + public void Init(string defaultGlobalConfigFolderPath) + { + if (!ProjectConfiguredFirstTime) + { + SetDefaultValues(); + ProjectConfiguredFirstTime = true; + } + + globalConfigFolderPath = InitPath(globalConfigFolderPath, defaultGlobalConfigFolderPath, GLOBAL_CONFIG_FOLDER_DEFAULT_PATH); + + exportFolderPath = InitPath(exportFolderPath, globalConfigFolderPath, EXPORT_FOLDER_NAME_DEFAULT); + + materialSavePath = InitPath(materialSavePath, exportFolderPath, MATERIAL_SAVE_FOLDER_NAME); + renderImageSavePath = InitPath(renderImageSavePath, exportFolderPath, RENDER_IMAGE_SAVE_FOLDER_NAME); + normalMapSavePath = InitPath(normalMapSavePath, exportFolderPath, NORMAL_MAP_SAVE_FOLDER_NAME); + gradientSavePath = InitPath(gradientSavePath, exportFolderPath, GRADIENT_SAVE_FOLDER_NAME); + atlasesSavePath = InitPath(atlasesSavePath, exportFolderPath, ATLASES_SAVE_FOLDER_NAME); + noiseSavePath = InitPath(noiseSavePath, exportFolderPath, NOISES_SAVE_FOLDER_NAME); + bakedShaderSavePath = InitPath(bakedShaderSavePath, exportFolderPath, BAKED_SHADER_FOLDER_NAME); + + bool foldersCreated = false; + CreateDefaultExportFoldersIfNotExist(ref foldersCreated); + + if (foldersCreated) + { + AssetDatabase.Refresh(); + } + } + + public void InitDefault() + { + + } + + public string InitPath(string path, string parentFolder, string defaultValue, bool isRoot = false) + { + string res = path; + if (!AssetDatabase.IsValidFolder(res)) + { + string defaultPath = defaultValue; + if (!isRoot) + { + defaultPath = Path.Combine(parentFolder, defaultValue); + } + res = defaultPath; + + EditorUtility.SetDirty(this); + } + + return res; + } + + public void CreateDefaultExportFoldersIfNotExist(ref bool foldersCreated) + { + CreateFolderIfNotExist(globalConfigFolderPath, ref foldersCreated); + + CreateFolderIfNotExist(exportFolderPath, ref foldersCreated); + + CreateFolderIfNotExist(materialSavePath, ref foldersCreated); + CreateFolderIfNotExist(renderImageSavePath, ref foldersCreated); + CreateFolderIfNotExist(normalMapSavePath, ref foldersCreated); + CreateFolderIfNotExist(gradientSavePath, ref foldersCreated); + CreateFolderIfNotExist(atlasesSavePath, ref foldersCreated); + CreateFolderIfNotExist(noiseSavePath, ref foldersCreated); + CreateFolderIfNotExist(bakedShaderSavePath, ref foldersCreated); + } + + private void CreateFolderIfNotExist(string absoluteFolderPath, ref bool foldersCreated) + { + if (!AssetDatabase.IsValidFolder(absoluteFolderPath)) + { + AssetDatabase.CreateFolder(Path.GetDirectoryName(absoluteFolderPath), Path.GetFileName(absoluteFolderPath)); + foldersCreated = foldersCreated || true; + } + } + + public void RefreshDefaultMaterial() + { + switch (projectType) + { + case ProjectType.STANDARD_BASIC: + this.defaultPreset = standardBasicMaterial; + break; + case ProjectType.STANDARD_PBR: + this.defaultPreset = standardPBRMaterial; + break; + case ProjectType.TOON: + this.defaultPreset = toonMaterial; + break; + case ProjectType.ALLIN13DSHADERLOOK: + this.defaultPreset = allIn13dDShaderLookMaterial; + break; + } + } + + public void RootFolderChanged(string oldPluginRootPath) + { + string oldGlobalConfigFolder = Path.Combine(oldPluginRootPath, GLOBAL_CONFIG_FOLDER_DEFAULT_PATH); + string oldExportFolder = GetExportFolderByParentFolder(oldGlobalConfigFolder); + + GlobalConfigFolderPath = UpdateRootFolders(oldPluginRootPath, GlobalConfigFolderPath, RootPluginPath, GLOBAL_CONFIG_FOLDER_DEFAULT_PATH); + + ExportFolderPath = UpdateRootFolders(oldGlobalConfigFolder, ExportFolderPath, GlobalConfigFolderPath, EXPORT_FOLDER_NAME_DEFAULT); + + MaterialSavePath = UpdateRootFolders(oldExportFolder, MaterialSavePath, ExportFolderPath, MATERIAL_SAVE_FOLDER_NAME); + RenderImageSavePath = UpdateRootFolders(oldExportFolder, RenderImageSavePath, ExportFolderPath, RENDER_IMAGE_SAVE_FOLDER_NAME); + NormalMapSavePath = UpdateRootFolders(oldExportFolder, NormalMapSavePath, ExportFolderPath, NORMAL_MAP_SAVE_FOLDER_NAME); + GradientSavePath = UpdateRootFolders(oldExportFolder, GradientSavePath, ExportFolderPath, GRADIENT_SAVE_FOLDER_NAME); + AtlasesSavePath = UpdateRootFolders(oldExportFolder, AtlasesSavePath, ExportFolderPath, ATLASES_SAVE_FOLDER_NAME); + NoiseSavePath = UpdateRootFolders(oldExportFolder, NoiseSavePath, ExportFolderPath, NOISES_SAVE_FOLDER_NAME); + BakedShaderSavePath = UpdateRootFolders(oldExportFolder, BakedShaderSavePath, ExportFolderPath, BAKED_SHADER_FOLDER_NAME); + } + + private string UpdateRootFolders(string oldRootFolder, string pathToCheck, string parentFolder, string relativePath) + { + string res = pathToCheck; + + string pathToCheckFull = Path.GetFullPath(pathToCheck); + string pathWithOldRootFull = Path.GetFullPath(Path.Combine(oldRootFolder, relativePath)); + + if (pathToCheckFull == pathWithOldRootFull) + { + res = Path.Combine(parentFolder, relativePath); + } + + return res; + } + + public static string GetRootPluginFolderPath() + { + Object mainAssemblyAsset = EditorUtils.FindAsset(MAIN_ASSEMBLY_NAME); + string assemblyPath = AssetDatabase.GetAssetPath(mainAssemblyAsset); + + string res = Path.GetDirectoryName(assemblyPath); + return res; + } + + public static bool CheckRootFolder(out string oldRootFolder) + { + bool res = false; + string newRootPluginFolderPath = GetRootPluginFolderPath(); + oldRootFolder = instance.RootPluginPath; + + if (newRootPluginFolderPath != instance.RootPluginPath && newRootPluginFolderPath != null) + { + string oldRootPath = instance.RootPluginPath; + instance.RootPluginPath = newRootPluginFolderPath; + + res = true; + } + + res = res && !string.IsNullOrEmpty(oldRootFolder); + + return res; + } + + public static void CheckGlobalConfigFolder() + { + string newGlobalConfigFolderPath = _instance.globalConfigFolderPath; + + if (newGlobalConfigFolderPath != instance.GlobalConfigFolderPath) + { + string oldGlobalConfigFolderPath = instance.GlobalConfigFolderPath; + instance.GlobalConfigFolderPath = newGlobalConfigFolderPath; + instance.RootFolderChanged(oldGlobalConfigFolderPath); + } + } + + public static void CheckMaterialReferences() + { + string allIn13DShaderLookMaterialPath = Path.Combine(_instance.RootPluginPath, "Editor/MaterialPresets/MAT_Preset_AllIn13DShaderLook.mat"); + string basicMaterialPath = Path.Combine(_instance.RootPluginPath, "Editor/MaterialPresets/MAT_Preset_Basic.mat"); + string standardPBRMaterialPath = Path.Combine(_instance.RootPluginPath, "Editor/MaterialPresets/MAT_Preset_StandardPBR.mat"); + string toonMaterialPath = Path.Combine(_instance.RootPluginPath, "Editor/MaterialPresets/MAT_Preset_Toon.mat"); + + if(_instance.allIn13dDShaderLookMaterial == null) + { + _instance.allIn13dDShaderLookMaterial = AssetDatabase.LoadAssetAtPath(allIn13DShaderLookMaterialPath); + } + + if(_instance.standardBasicMaterial == null) + { + _instance.standardBasicMaterial = AssetDatabase.LoadAssetAtPath(basicMaterialPath); + } + + if(_instance.standardPBRMaterial == null) + { + _instance.standardPBRMaterial = AssetDatabase.LoadAssetAtPath(standardPBRMaterialPath); + } + + if(_instance.toonMaterial == null) + { + _instance.toonMaterial = AssetDatabase.LoadAssetAtPath(toonMaterialPath); + } + + if(_instance.defaultPreset == null) + { + _instance.RefreshDefaultMaterial(); + } + } + + public void SetDefaultValues() + { + projectType = ProjectType.STANDARD_PBR; + defaultPreset = standardPBRMaterial; + + EditorUtility.SetDirty(this); + } + + public void Save() + { + EditorUtility.SetDirty(this); + AssetDatabase.SaveAssetIfDirty(this); + } + + public static string GetDefaultConfigFolderPath() + { + string res = string.Empty; +#if ALLIN13DSHADER_DEVELOP + res = Path.Combine("Assets", ALLIN13SHADER_CONFIG_DEFAULT_FOLDER_NAME); +#else + res = Path.Combine(_instance.RootPluginPath, ALLIN13SHADER_CONFIG_DEFAULT_FOLDER_NAME); +#endif + return res; + } + + public static string GetParentConfigFolderPath() + { + string res = string.Empty; +#if ALLIN13DSHADER_DEVELOP + res = "Assets"; +#else + res = instance.RootPluginPath; +#endif + return res; + } + + public static string GetExportFolderByParentFolder(string rootFolder) + { + string res = string.Empty; + +#if ALLIN13DSHADER_DEVELOP + res = Path.Combine("Assets", EXPORT_FOLDER_NAME_DEFAULT); +#else + res = Path.Combine(rootFolder, EXPORT_FOLDER_NAME_DEFAULT); +#endif + + return res; + } + + public static GlobalConfiguration SaveInstanceAsAsset() + { + string defaultConfigFolderPath = GetDefaultConfigFolderPath(); + string parentFolder = GetParentConfigFolderPath(); + string defaultGlobalConfigurationPath = Path.Combine(defaultConfigFolderPath, GLOBAL_CONFIGURATION_ASSET_NAME); + + if (!AssetDatabase.IsValidFolder(defaultConfigFolderPath)) + { + AssetDatabase.CreateFolder(Path.GetDirectoryName(defaultConfigFolderPath), Path.GetFileName(defaultConfigFolderPath)); + } + + _instance.Init(parentFolder); + AssetDatabase.CreateAsset(_instance, defaultGlobalConfigurationPath); + + return _instance; + } + + public static GlobalConfiguration CreateInstanceIfNeeded(out bool globalConfigInstanceCreated) + { + GlobalConfiguration res = EditorUtils.FindAsset("GlobalConfiguration"); + globalConfigInstanceCreated = false; + + if (res == null) + { + res = ScriptableObject.CreateInstance(); + globalConfigInstanceCreated = true; + } + + return res; + } + + public static void InitIfNeeded() + { + bool globalConfigInstanceCreated = false; + bool needToCreateInstance = _instance == null || !AssetDatabase.IsMainAsset(_instance); + + if (needToCreateInstance) + { + _instance = CreateInstanceIfNeeded(out globalConfigInstanceCreated); + } + + string oldRootPath = string.Empty; + bool rootFolderChanged = CheckRootFolder(out oldRootPath); + if (globalConfigInstanceCreated) + { + SaveInstanceAsAsset(); + } + else + { + string parentFolder = GetParentConfigFolderPath(); + _instance.Init(parentFolder); + } + + if (rootFolderChanged) + { + instance.RootFolderChanged(oldRootPath); + } + + CheckMaterialReferences(); + + SessionState.SetString(ConstantsRuntime.SESSION_KEY_ROOT_PLUGIN_PATH, _instance.rootPluginPath); + } + + public static void SetupShadersReferences() + { + if(_instance.shStandard == null) + { + _instance.shStandard = Shader.Find("AllIn13DShader/AllIn13DShader"); + } + + if(_instance.shStandardNoShadowCaster == null) + { + _instance.shStandardNoShadowCaster = Shader.Find("AllIn13DShader/AllIn13DShader_NoShadowCaster"); + } + + if(_instance.shOutline == null) + { + _instance.shOutline = Shader.Find("AllIn13DShader/AllIn13DShaderOutline"); + } + + if(_instance.shOutlineNoShadowCaster == null) + { + _instance.shOutlineNoShadowCaster = Shader.Find("AllIn13DShader/AllIn13DShaderOutline_NoShadowCaster"); + } + } + + public EffectsProfileCollection GetEffectsProfileCollection() + { + return effectsProfileCollection; + } + + public void SetEffectsProfileCollection(EffectsProfileCollection effectsProfileCollection) + { + this.effectsProfileCollection = effectsProfileCollection; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/GlobalConfiguration.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/GlobalConfiguration.cs.meta new file mode 100644 index 0000000..2c4defd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/GlobalConfiguration.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 592122c0ab3d6c04d85891bcd2f332bc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/GlobalConfiguration.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/GradientTexture.cs b/Assets/Plugins/AllIn13DShader/Editor/GradientTexture.cs new file mode 100644 index 0000000..0440cb3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/GradientTexture.cs @@ -0,0 +1,10 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class GradientTexture : ScriptableObject + { + public Texture texture; + public Gradient gradient; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/GradientTexture.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/GradientTexture.cs.meta new file mode 100644 index 0000000..37b8a60 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/GradientTexture.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: cb204018ddc8dbc43a4340c074e1a919 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/GradientTexture.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/KeywordsOp.cs b/Assets/Plugins/AllIn13DShader/Editor/KeywordsOp.cs new file mode 100644 index 0000000..f355486 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/KeywordsOp.cs @@ -0,0 +1,8 @@ +namespace AllIn13DShader +{ + public enum KeywordsOp + { + OR = 0, + AND = 1, + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/KeywordsOp.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/KeywordsOp.cs.meta new file mode 100644 index 0000000..ed7f44a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/KeywordsOp.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 971b7074914259f44a376305157e0822 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/KeywordsOp.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter.meta new file mode 100644 index 0000000..4c65f8d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c2e4adba0bfc32e469be122097acbff6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data.meta new file mode 100644 index 0000000..9c6eb6b --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2de17220d6a39f349bf8e674591e88e0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionConfig.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionConfig.asset new file mode 100644 index 0000000..fb82ae6 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionConfig.asset @@ -0,0 +1,27 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 466e422414ab2d84fa4f40d216c7e612, type: 3} + m_Name: ConversionConfig + m_EditorClassIdentifier: + shaderFrom: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + isPBR: 1 + conversionProperties: + - {fileID: 11400000, guid: be6fa034baa49d141b3a14ecbfef8363, type: 2} + - {fileID: 11400000, guid: 5f51682703f2a9b4f88d479ec7f33aed, type: 2} + - {fileID: 11400000, guid: ea00c9ca2c9d98849a41cccd5e6ac9b0, type: 2} + - {fileID: 11400000, guid: 56213c9e141f53a4f9263fbf76279d4f, type: 2} + - {fileID: 11400000, guid: e7b13351ed21ed341849831601efb931, type: 2} + - {fileID: 11400000, guid: 761eb2065074b88479ef7cd78c2c1f7b, type: 2} + - {fileID: 11400000, guid: b4b7a011ebc4eb346beb6c73e006f172, type: 2} + - {fileID: 11400000, guid: baada5bf5b0f7a5429fa3aa12b6c5182, type: 2} + - {fileID: 11400000, guid: dd741cd0153185b40b7e7300dc15bf26, type: 2} + - {fileID: 11400000, guid: 44abc7f45dbbe9b42804ddfc9444a7cc, type: 2} diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionConfig.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionConfig.asset.meta new file mode 100644 index 0000000..f7f7784 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionConfig.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 465436cd31fea2b41a5ab2c2bbaf1b85 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionConfig.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMap.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMap.asset new file mode 100644 index 0000000..9028f5e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMap.asset @@ -0,0 +1,21 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 95c835d611027ef4e8f42f58386c1d3f, type: 3} + m_Name: ConversionProperty_AOMap + m_EditorClassIdentifier: + propertyType: 1 + propertyName: _AOMap + nameTo: + belongingToEffect: AOMAP + requiredProperty: 1 + alternativeNames: + - _OcclusionMap diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMap.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMap.asset.meta new file mode 100644 index 0000000..de3fe7c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMap.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: be6fa034baa49d141b3a14ecbfef8363 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMap.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMapStrength.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMapStrength.asset new file mode 100644 index 0000000..07f8f55 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMapStrength.asset @@ -0,0 +1,21 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 95c835d611027ef4e8f42f58386c1d3f, type: 3} + m_Name: ConversionProperty_AOMapStrength + m_EditorClassIdentifier: + propertyType: 0 + propertyName: _AOMapStrength + nameTo: + belongingToEffect: AOMAP + requiredProperty: 0 + alternativeNames: + - _OcclusionStrength diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMapStrength.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMapStrength.asset.meta new file mode 100644 index 0000000..c04ed26 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMapStrength.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 5f51682703f2a9b4f88d479ec7f33aed +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_AOMapStrength.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionColor.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionColor.asset new file mode 100644 index 0000000..357b127 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionColor.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 95c835d611027ef4e8f42f58386c1d3f, type: 3} + m_Name: ConversionProperty_EmissionColor + m_EditorClassIdentifier: + propertyType: 2 + propertyName: _EmissionColor + nameTo: + belongingToEffect: EMISSION + requiredProperty: 0 + alternativeNames: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionColor.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionColor.asset.meta new file mode 100644 index 0000000..5ca22f2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionColor.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 44abc7f45dbbe9b42804ddfc9444a7cc +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionColor.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionMap.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionMap.asset new file mode 100644 index 0000000..755ce14 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionMap.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 95c835d611027ef4e8f42f58386c1d3f, type: 3} + m_Name: ConversionProperty_EmissionMap + m_EditorClassIdentifier: + propertyType: 1 + propertyName: _EmissionMap + nameTo: + belongingToEffect: EMISSION + requiredProperty: 1 + alternativeNames: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionMap.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionMap.asset.meta new file mode 100644 index 0000000..5d7de39 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionMap.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: dd741cd0153185b40b7e7300dc15bf26 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_EmissionMap.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainColor.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainColor.asset new file mode 100644 index 0000000..3f91b05 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainColor.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 95c835d611027ef4e8f42f58386c1d3f, type: 3} + m_Name: ConversionProperty_MainColor + m_EditorClassIdentifier: + propertyType: 2 + propertyName: _Color + nameTo: + belongingToEffect: + requiredProperty: 0 + alternativeNames: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainColor.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainColor.asset.meta new file mode 100644 index 0000000..5b71577 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainColor.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: ea00c9ca2c9d98849a41cccd5e6ac9b0 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainColor.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainTex.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainTex.asset new file mode 100644 index 0000000..db1de86 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainTex.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 95c835d611027ef4e8f42f58386c1d3f, type: 3} + m_Name: ConversionProperty_MainTex + m_EditorClassIdentifier: + propertyType: 1 + propertyName: _MainTex + nameTo: + belongingToEffect: + requiredProperty: 0 + alternativeNames: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainTex.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainTex.asset.meta new file mode 100644 index 0000000..694ce0a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainTex.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 56213c9e141f53a4f9263fbf76279d4f +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_MainTex.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Metallic.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Metallic.asset new file mode 100644 index 0000000..b7a0be6 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Metallic.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 95c835d611027ef4e8f42f58386c1d3f, type: 3} + m_Name: ConversionProperty_Metallic + m_EditorClassIdentifier: + propertyType: 0 + propertyName: _Metallic + nameTo: + belongingToEffect: + requiredProperty: 0 + alternativeNames: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Metallic.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Metallic.asset.meta new file mode 100644 index 0000000..3a16f43 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Metallic.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: b4b7a011ebc4eb346beb6c73e006f172 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Metallic.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMap.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMap.asset new file mode 100644 index 0000000..cf90e67 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMap.asset @@ -0,0 +1,21 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 95c835d611027ef4e8f42f58386c1d3f, type: 3} + m_Name: ConversionProperty_NormalMap + m_EditorClassIdentifier: + propertyType: 1 + propertyName: _NormalMap + nameTo: + belongingToEffect: NORMAL_MAP + requiredProperty: 1 + alternativeNames: + - _BumpMap diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMap.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMap.asset.meta new file mode 100644 index 0000000..3210c38 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMap.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: e7b13351ed21ed341849831601efb931 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMap.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMapStrength.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMapStrength.asset new file mode 100644 index 0000000..4e4b4c8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMapStrength.asset @@ -0,0 +1,21 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 95c835d611027ef4e8f42f58386c1d3f, type: 3} + m_Name: ConversionProperty_NormalMapStrength + m_EditorClassIdentifier: + propertyType: 0 + propertyName: _NormalStrength + nameTo: + belongingToEffect: NORMAL_MAP + requiredProperty: 0 + alternativeNames: + - _BumpScale diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMapStrength.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMapStrength.asset.meta new file mode 100644 index 0000000..a71ed47 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMapStrength.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 761eb2065074b88479ef7cd78c2c1f7b +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_NormalMapStrength.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Smoothness.asset b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Smoothness.asset new file mode 100644 index 0000000..1546d9e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Smoothness.asset @@ -0,0 +1,21 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 95c835d611027ef4e8f42f58386c1d3f, type: 3} + m_Name: ConversionProperty_Smoothness + m_EditorClassIdentifier: + propertyType: 0 + propertyName: _Smoothness + nameTo: + belongingToEffect: + requiredProperty: 0 + alternativeNames: + - _Glossiness diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Smoothness.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Smoothness.asset.meta new file mode 100644 index 0000000..8571f1e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Smoothness.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: baada5bf5b0f7a5429fa3aa12b6c5182 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Data/ConversionProperty_Smoothness.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts.meta new file mode 100644 index 0000000..d1ee1ae --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f59fc50ffb03c404295028ac99ed925b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionConfig.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionConfig.cs new file mode 100644 index 0000000..e9b9176 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionConfig.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class ConversionConfig : ScriptableObject + { + public ConversionProperty[] conversionProperties; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionConfig.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionConfig.cs.meta new file mode 100644 index 0000000..dcf771a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionConfig.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 466e422414ab2d84fa4f40d216c7e612 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionConfig.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionProperty.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionProperty.cs new file mode 100644 index 0000000..dc395a3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionProperty.cs @@ -0,0 +1,17 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class ConversionProperty : ScriptableObject + { + public ConversionPropertyType propertyType; + public string propertyName; + + [Header("Effect")] + public string belongingToEffect; + public bool requiredProperty; + + [Header("Alternative Names")] + public string[] alternativeNames; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionProperty.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionProperty.cs.meta new file mode 100644 index 0000000..6403f69 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionProperty.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 95c835d611027ef4e8f42f58386c1d3f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionProperty.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionPropertyType.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionPropertyType.cs new file mode 100644 index 0000000..e92cd89 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionPropertyType.cs @@ -0,0 +1,10 @@ +namespace AllIn13DShader +{ + public enum ConversionPropertyType + { + FLOAT, + TEXTURE, + COLOR, + VECTOR, + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionPropertyType.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionPropertyType.cs.meta new file mode 100644 index 0000000..28c5684 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionPropertyType.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: f4436880cfef3ea4bab5b36df4eb5345 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConversionPropertyType.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterGeneral.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterGeneral.cs new file mode 100644 index 0000000..b77cdc5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterGeneral.cs @@ -0,0 +1,199 @@ +using UnityEngine; +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + public class ConverterGeneral + { + protected Material from; + protected Material target; + + protected ConversionConfig conversionConfig; + protected PropertiesConfigCollection propertiesConfigCollection; + protected PropertiesConfig propertiesConfig; + + public virtual void ApplyConversion(Material from, Material target) + { + this.from = from; + this.target = target; + + this.conversionConfig = EditorUtils.FindAssetByName("ConversionConfig"); + this.propertiesConfigCollection = EditorUtils.FindAssetByName("PropertiesConfigCollection"); + this.propertiesConfig = propertiesConfigCollection.FindPropertiesConfigByShader(target.shader); + + for (int i = 0; i < conversionConfig.conversionProperties.Length; i++) + { + ConversionProperty conversionProperty = conversionConfig.conversionProperties[i]; + + bool propertiveActive = false; + ApplyConversionProperty(conversionProperty, from, target, ref propertiveActive); + + if (!string.IsNullOrEmpty(conversionProperty.belongingToEffect) && conversionProperty.requiredProperty && propertiveActive) + { + AllIn13DEffectConfig effectConfig = propertiesConfig.FindEffectConfigByID(conversionProperty.belongingToEffect); + EnableEffect(effectConfig); + } + } + + target.renderQueue = from.renderQueue; + } + + protected void SetEnableEffect(string effectID, bool enabled) + { + AllIn13DEffectConfig effectConfig = propertiesConfig.FindEffectConfigByID(effectID); + + if (enabled) + { + EnableEffect(effectConfig); + } + else + { + DisableEffect(effectConfig); + } + } + + protected void EnableEffect(AllIn13DEffectConfig effectConfig) + { + if (effectConfig.keywords.Count == 1) + { + target.EnableKeyword(effectConfig.keywords[0].keyword); + target.SetFloat(effectConfig.keywordPropertyName, 1f); + } + } + + protected void DisableEffect(string effectID) + { + AllIn13DEffectConfig effectConfig = propertiesConfig.FindEffectConfigByID(effectID); + DisableEffect(effectConfig); + } + + protected void DisableEffect(AllIn13DEffectConfig effectConfig) + { + for (int i = 0; i < effectConfig.keywords.Count; i++) + { + target.DisableKeyword(effectConfig.keywords[i].keyword); + } + + target.SetFloat(effectConfig.keywordPropertyName, 0f); + } + + protected void EnablePBR() + { + AllIn13DEffectConfig shadingModelEffect = propertiesConfig.FindEffectConfigByID("SHADINGMODEL"); + + DisableEffect(shadingModelEffect); + + string pbrKeyword = shadingModelEffect.keywords[1].keyword; + + target.EnableKeyword(pbrKeyword); + target.SetFloat("_ShadingModel", 1.0f); + } + + protected void EnableLightModelClassic() + { + AllIn13DEffectConfig lightModelEffect = propertiesConfig.FindEffectConfigByID("LIGHTMODEL"); + + DisableEffect(lightModelEffect); + + string lightModelClassicKeyword = lightModelEffect.keywords[1].keyword; + + target.EnableKeyword(lightModelClassicKeyword); + target.SetFloat(lightModelEffect.keywordPropertyName, 1.0f); + } + + protected void EnableSpecularClassic() + { + AllIn13DEffectConfig specularModelEffect = propertiesConfig.FindEffectConfigByID("SPECULARMODEL"); + + DisableEffect(specularModelEffect); + + string specularModelClassicKeyword = specularModelEffect.keywords[1].keyword; + + target.EnableKeyword(specularModelClassicKeyword); + target.SetFloat(specularModelEffect.keywordPropertyName, 1.0f); + } + + protected void SetBlendSrc(UnityEngine.Rendering.BlendMode blendMode) + { + target.SetInt("_BlendSrc", (int)blendMode); + } + + protected void SetBlendDst(UnityEngine.Rendering.BlendMode blendMode) + { + target.SetInt("_BlendDst", (int)blendMode); + } + + protected void SetAlphaPreset() + { + target.SetFloat("_RenderPreset", 2); + } + + protected void SetOpaquePreset() + { + target.SetFloat("_RenderPreset", 1); + } + + protected void ApplyConversionProperty(ConversionProperty conversionProperty, Material from, Material target, ref bool propertyActive) + { + string propertyNameFrom = string.Empty; + string propertyNameTarget = conversionProperty.propertyName; + + if (from.HasProperty(conversionProperty.propertyName)) + { + propertyNameFrom = conversionProperty.propertyName; + } + else + { + for (int i = 0; i < conversionProperty.alternativeNames.Length; i++) + { + if (from.HasProperty(conversionProperty.alternativeNames[i])) + { + propertyNameFrom = conversionProperty.alternativeNames[i]; + break; + } + } + } + + if (!string.IsNullOrEmpty(propertyNameFrom)) + { + switch (conversionProperty.propertyType) + { + case ConversionPropertyType.TEXTURE: + Texture texValue = from.GetTexture(propertyNameFrom); + Vector2 texOffset = from.GetTextureOffset(propertyNameFrom); + Vector2 texScale = from.GetTextureScale(propertyNameFrom); + + target.SetTexture(propertyNameTarget, texValue); + + target.SetTextureOffset(propertyNameTarget, texOffset); + target.SetTextureScale(propertyNameTarget, texScale); + + propertyActive = texValue != null; + + break; + case ConversionPropertyType.FLOAT: + float floatValue = from.GetFloat(propertyNameFrom); + target.SetFloat(propertyNameTarget, floatValue); + + propertyActive = true; + + break; + case ConversionPropertyType.COLOR: + Color colorValue = from.GetColor(propertyNameFrom); + target.SetColor(propertyNameTarget, colorValue); + + propertyActive = true; + + break; + case ConversionPropertyType.VECTOR: + Vector4 vectorValue = from.GetVector(propertyNameFrom); + target.SetVector(propertyNameTarget, vectorValue); + + propertyActive = true; + + break; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterGeneral.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterGeneral.cs.meta new file mode 100644 index 0000000..4318eac --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterGeneral.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: fe8d92d4b6d87fd4892ac9b7eaa2bd37 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterGeneral.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandard.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandard.cs new file mode 100644 index 0000000..8ed5053 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandard.cs @@ -0,0 +1,47 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class ConverterStandard : ConverterGeneral + { + public override void ApplyConversion(Material from, Material target) + { + base.ApplyConversion(from, target); + + DisableEffect("ALPHA_CUTOFF"); + + bool emissionEffectEnabled = from.IsKeywordEnabled("_EMISSION"); + SetEnableEffect("EMISSION", emissionEffectEnabled); + + bool normalMapEffectEnabled = from.IsKeywordEnabled("_NORMALMAP"); + SetEnableEffect("NORMAL_MAP", normalMapEffectEnabled); + + EnableLightModelClassic(); + + EnablePBR(); + + target.SetFloat("_ReflectionsAtten", 1.0f); + + bool specularEnabled = !from.IsKeywordEnabled("_SPECULARHIGHLIGHTS_OFF"); + if (specularEnabled) + { + EnableSpecularClassic(); + target.SetFloat("_SpecularAtten", 1.0f); + } + else + { + DisableEffect("SPECULARMODEL"); + } + + DisableEffect("RIM_LIGHTING"); + + //Blending Mode + ConvertBlending(); + } + + protected virtual void ConvertBlending() + { + + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandard.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandard.cs.meta new file mode 100644 index 0000000..e59cf2d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandard.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: e0584ca1f69659048b2a800ed4d52cd8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandard.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandardBIRP.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandardBIRP.cs new file mode 100644 index 0000000..916b529 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandardBIRP.cs @@ -0,0 +1,29 @@ +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + public class ConverterStandardBIRP : ConverterStandard + { + protected override void ConvertBlending() + { + if (from.IsKeywordEnabled("_ALPHAPREMULTIPLY_ON")) + { + SetBlendSrc(UnityEngine.Rendering.BlendMode.One); + SetBlendDst(UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); + SetAlphaPreset(); + } + else if (from.IsKeywordEnabled("_ALPHABLEND_ON")) + { + SetBlendSrc(UnityEngine.Rendering.BlendMode.SrcAlpha); + SetBlendDst(UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); + SetAlphaPreset(); + } + else + { + SetBlendSrc(UnityEngine.Rendering.BlendMode.One); + SetBlendDst(UnityEngine.Rendering.BlendMode.Zero); + SetOpaquePreset(); + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandardBIRP.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandardBIRP.cs.meta new file mode 100644 index 0000000..6582dfe --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandardBIRP.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 1a12bb5293276e74daff29adac53e710 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterStandardBIRP.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterURPLit.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterURPLit.cs new file mode 100644 index 0000000..3768a3c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterURPLit.cs @@ -0,0 +1,32 @@ +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + public class ConverterURPLit : ConverterStandard + { + protected override void ConvertBlending() + { + if (from.IsKeywordEnabled("_SURFACE_TYPE_TRANSPARENT")) + { + if (from.IsKeywordEnabled("_ALPHAPREMULTIPLY_ON")) + { + SetBlendSrc(UnityEngine.Rendering.BlendMode.One); + SetBlendDst(UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); + } + else + { + SetBlendSrc(UnityEngine.Rendering.BlendMode.SrcAlpha); + SetBlendDst(UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); + } + + SetAlphaPreset(); + } + else + { + SetBlendSrc(UnityEngine.Rendering.BlendMode.One); + SetBlendDst(UnityEngine.Rendering.BlendMode.Zero); + SetOpaquePreset(); + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterURPLit.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterURPLit.cs.meta new file mode 100644 index 0000000..c085078 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterURPLit.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: eda76fc9b5ca6914ea7ea1048cecba9d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/ConverterURPLit.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/MaterialConverterTool.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/MaterialConverterTool.cs new file mode 100644 index 0000000..bd0ca9e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/MaterialConverterTool.cs @@ -0,0 +1,248 @@ +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public static class MaterialConverterTool + { + private const int OVERRIDE = 0; + private const int CANCEL = 1; + private const int KEEP_ORIGINALS = 2; + + [MenuItem(itemName: "Assets/AllIn1/Convert ALL materials to AllIn13DShader", isValidateFunction: true)] + public static bool ValidateBatchConvert() + { + bool res = true; + + Object[] selectedAssets = Selection.GetFiltered(SelectionMode.Assets); + foreach (Object asset in selectedAssets) + { + string path = AssetDatabase.GetAssetPath(asset); + + bool isValidFolder = AssetDatabase.IsValidFolder(path); + + Material mat = AssetDatabase.LoadAssetAtPath(path); + bool isMaterial = mat != null; + + res = res && (isValidFolder || isMaterial); + } + + return res; + } + + [MenuItem(itemName: "Assets/AllIn1/Convert ALL materials to AllIn13DShader")] + public static void BatchConvert() + { + Object[] selectedAssets = Selection.GetFiltered(SelectionMode.Assets); + HashSet pathsToConvert = CollectPathsToConvert(selectedAssets); + + string title = "Converting materials to AllIn13D"; + string message = $"You are about to convert {pathsToConvert.Count} materials to AllIn13D"; + string okButton = "Convert and Override"; + string altButton = "Convert and keep originals"; + string cancelButton = "Cancel"; + + + int dialog = EditorUtility.DisplayDialogComplex(title, message, okButton, cancelButton, altButton); + + if(dialog == CANCEL) { return; } + + ConvertMaterials(pathsToConvert, dialog); + } + + [MenuItem(itemName: "Assets/AllIn1/Convert Standard materials to AllIn13DShader")] + public static void BatchConvertStandardMats() + { + Object[] selectedAssets = Selection.GetFiltered(SelectionMode.Assets); + HashSet pathsToConvert = CollectPathsToConvert(selectedAssets); + + //Remove pathsToConvert of materials that have a shader name that contains Standard + HashSet standardMaterialPaths = new HashSet(pathsToConvert.Count); + foreach(string path in pathsToConvert) + { + Material mat = AssetDatabase.LoadAssetAtPath(path); + if(mat != null && mat.shader != null && mat.shader.name.Contains("Standard")) + standardMaterialPaths.Add(path); + } + + string title = "Converting Standard materials to AllIn13D"; + string message = $"You are about to convert {standardMaterialPaths.Count} Standard materials to AllIn13D"; + string okButton = "Convert and Override"; + string altButton = "Convert and keep originals"; + string cancelButton = "Cancel"; + + int dialog = EditorUtility.DisplayDialogComplex(title, message, okButton, cancelButton, altButton); + + if(dialog == CANCEL) return; + + ConvertMaterials(standardMaterialPaths, dialog); + } + + private static HashSet CollectPathsToConvert(Object[] selectedAssets) + { + HashSet res = new HashSet(); + + foreach (Object asset in selectedAssets) + { + string path = AssetDatabase.GetAssetPath(asset); + + if (asset is Material) + { + res.Add(path); + } + else + { + string[] materialsInFolderGUIDs = AssetDatabase.FindAssets("t: Material", new string[] { path }); + foreach (string guid in materialsInFolderGUIDs) + { + res.Add(AssetDatabase.GUIDToAssetPath(guid)); + } + } + } + + return res; + } + + private static void ConvertMaterials(HashSet materialsPaths, int dialog) + { + Undo.IncrementCurrentGroup(); + + Material matTemplate = GlobalConfiguration.instance.defaultPreset; + foreach (string path in materialsPaths) + { + ConvertMaterial(path, matTemplate, dialog); + } + + Undo.SetCurrentGroupName("Materials conversion to AllIn13DShader"); + + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + + private static void ConvertMaterial(string path, Material matTemplate, int dialog) + { + Material matFrom = AssetDatabase.LoadAssetAtPath(path); + Material target = new Material(matTemplate); + + ApplyConversion(matFrom, target); + + string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path); + string folder = Path.GetDirectoryName(path); + string fileName = Path.GetFileName(path); + + string fileNameNewAsset = fileNameWithoutExtension + "_AllIn13D" + ".mat"; + string pathNewAsset = Path.Combine(folder, fileNameNewAsset); + + if (dialog == KEEP_ORIGINALS) + { + AssetDatabase.CreateAsset(target, pathNewAsset); + Object createdObject = AssetDatabase.LoadAssetAtPath(pathNewAsset); + } + else if (dialog == OVERRIDE) + { + Undo.RecordObject(matFrom, "Material converted"); + + matFrom.shader = target.shader; + matFrom.CopyMatchingPropertiesFromMaterial(target); + EditorUtility.SetDirty(matFrom); + } + } + + public static Material Convert(Shader shader, Material from) + { + Material res = new Material(shader); + Texture normalMap = from.GetTexture("_BumpMap"); + + if (normalMap != null) + { + res.SetTexture("_NormalMap", normalMap); + } + + return res; + } + + public static ConverterGeneral GetConverterByShader(Shader shader) + { + ConverterGeneral res = new ConverterGeneral(); + + if(shader.name == "Standard") + { + res = new ConverterStandardBIRP(); + } + else if(shader.name == "Universal Render Pipeline/Lit") + { + res = new ConverterURPLit(); + } + + return res; + } + + public static void ApplyConversion(Material from, Material target) + { + if(from != null && target != null) + { + ConverterGeneral converter = GetConverterByShader(from.shader); + converter.ApplyConversion(from, target); + } + } + + public static void ApplyConversionProperty(ConversionProperty conversionProperty, Material from, Material target, ref bool propertyActive) + { + string propertyNameFrom = string.Empty; + string propertyNameTarget = conversionProperty.propertyName; + + if (from.HasProperty(conversionProperty.propertyName)) + { + propertyNameFrom = conversionProperty.propertyName; + } + else + { + for (int i = 0; i < conversionProperty.alternativeNames.Length; i++) + { + if (from.HasProperty(conversionProperty.alternativeNames[i])) + { + propertyNameFrom = conversionProperty.alternativeNames[i]; + break; + } + } + } + + if (!string.IsNullOrEmpty(propertyNameFrom)) + { + switch (conversionProperty.propertyType) + { + case ConversionPropertyType.TEXTURE: + Texture texValue = from.GetTexture(propertyNameFrom); + target.SetTexture(propertyNameTarget, texValue); + + propertyActive = texValue != null; + + break; + case ConversionPropertyType.FLOAT: + float floatValue = from.GetFloat(propertyNameFrom); + target.SetFloat(propertyNameTarget, floatValue); + + propertyActive = true; + + break; + case ConversionPropertyType.COLOR: + Color colorValue = from.GetColor(propertyNameFrom); + target.SetColor(propertyNameTarget, colorValue); + + propertyActive = true; + + break; + case ConversionPropertyType.VECTOR: + Vector4 vectorValue = from.GetVector(propertyNameFrom); + target.SetVector(propertyNameTarget, vectorValue); + + propertyActive = true; + + break; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/MaterialConverterTool.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/MaterialConverterTool.cs.meta new file mode 100644 index 0000000..0963afe --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/MaterialConverterTool.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: c83ec1dea52056c478b8a512b7ea53a8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialConverter/Scripts/MaterialConverterTool.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride.meta new file mode 100644 index 0000000..50caaf2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 849e8daf08a868a448e013b584ab1c98 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts.meta new file mode 100644 index 0000000..0f8fd61 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5b2ef73a7affcda479bef19e0eb16a13 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/AbstractEffectOverride.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/AbstractEffectOverride.cs new file mode 100644 index 0000000..791cbf4 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/AbstractEffectOverride.cs @@ -0,0 +1,87 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace AllIn13DShader +{ + public abstract class AbstractEffectOverride + { + public List propertyOverrides; + + public string displayName; + public string propertyName; + + public bool overrideEnabled; + + public List keywords; + + public AbstractEffectOverride(AllIn13DEffectConfig effectConfig) + { + this.displayName = effectConfig.displayName; + this.propertyName = effectConfig.keywordPropertyName; + this.keywords = new List(effectConfig.keywords); + + this.propertyOverrides = new List(); + } + + public void AddPropertyOverride(EffectProperty effectProperty, Shader shader) + { + PropertyOverride propertyOverride = new PropertyOverride(this, effectProperty, shader); + + AddPropertyOverride(propertyOverride); + } + + public void AddPropertyOverride(int propertyIndex, Shader shader) + { + PropertyOverride propertyOverride = new PropertyOverride(this, propertyIndex, shader); + + AddPropertyOverride(propertyOverride); + } + + private void AddPropertyOverride(PropertyOverride propertyOverride) + { + if (!propertyOverrides.Contains(propertyOverride)) + { + propertyOverrides.Add(propertyOverride); + } + } + + public virtual void ApplyChangesToMaterial(Material mat) + { + if (overrideEnabled) + { + ApplyMainPropertyChanges(mat); + } + + for(int i = 0; i < propertyOverrides.Count; i++) + { + propertyOverrides[i].ApplyChangesToMaterial(mat); + } + } + + protected abstract void ApplyMainPropertyChanges(Material mat); + + public bool RemovePropertyOverride(PropertyOverride propertyOverrideToRemove) + { + bool res = propertyOverrides.Remove(propertyOverrideToRemove); + return res; + } + + public override bool Equals(object obj) + { + bool res = false; + + if(obj is AbstractEffectOverride) + { + AbstractEffectOverride abstractEffectOverride = (AbstractEffectOverride)obj; + res = propertyName == abstractEffectOverride.propertyName; + } + + return res; + } + + public override int GetHashCode() + { + return propertyName.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/AbstractEffectOverride.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/AbstractEffectOverride.cs.meta new file mode 100644 index 0000000..bad2d9c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/AbstractEffectOverride.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 0611bcd764908134fa1f7a375b5e9e53 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/AbstractEffectOverride.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectEnumOverride.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectEnumOverride.cs new file mode 100644 index 0000000..b0d8039 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectEnumOverride.cs @@ -0,0 +1,33 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class EffectEnumOverride : AbstractEffectOverride + { + public string[] enumOptions; + + public int index; + + public EffectEnumOverride(AllIn13DEffectConfig effectConfig) : base(effectConfig) + { + enumOptions = new string[effectConfig.keywords.Count]; + for(int i = 0; i < enumOptions.Length; i++) + { + enumOptions[i] = effectConfig.keywords[i].displayName; + } + } + + protected override void ApplyMainPropertyChanges(Material mat) + { + for(int i = 0; i < keywords.Count; i++) + { + mat.DisableKeyword(keywords[i].keyword); + } + + mat.EnableKeyword(keywords[index].keyword); + mat.SetFloat(propertyName, (float)index); + + MaterialUtils.CheckMaterialShader(mat); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectEnumOverride.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectEnumOverride.cs.meta new file mode 100644 index 0000000..0b6f01e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectEnumOverride.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: f4ad01e8d27a2b3499bce2fe41f386c1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectEnumOverride.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectToggleOverride.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectToggleOverride.cs new file mode 100644 index 0000000..9b7b2c0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectToggleOverride.cs @@ -0,0 +1,30 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class EffectToggleOverride : AbstractEffectOverride + { + public bool boolValue; + + public EffectToggleOverride(AllIn13DEffectConfig effectConfig) : base(effectConfig) + { + + } + + protected override void ApplyMainPropertyChanges(Material mat) + { + if (boolValue) + { + mat.EnableKeyword(keywords[0].keyword); + mat.SetFloat(propertyName, 1f); + } + else + { + mat.DisableKeyword(keywords[0].keyword); + mat.SetFloat(propertyName, 0f); + } + + MaterialUtils.CheckMaterialShader(mat); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectToggleOverride.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectToggleOverride.cs.meta new file mode 100644 index 0000000..afddde9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectToggleOverride.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 87a78a29536838242b8abe925b7597bb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/EffectToggleOverride.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/MaterialOverrideData.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/MaterialOverrideData.cs new file mode 100644 index 0000000..03990b3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/MaterialOverrideData.cs @@ -0,0 +1,470 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + [System.Serializable] + public class MaterialOverrideData : ScriptableObject + { + public class MaterialOverride + { + public Material sourceMaterial; + public Material previewMaterial; + + public MaterialOverride(Material sourceMaterial) + { + this.sourceMaterial = sourceMaterial; + + if(sourceMaterial == null) + { + this.previewMaterial = null; + } + else + { + this.previewMaterial = new Material(sourceMaterial); + this.previewMaterial.name = this.previewMaterial.name + "_PREVIEW"; + } + } + + public void ApplyPreviewToSource() + { + sourceMaterial.CopyMatchingPropertiesFromMaterial(previewMaterial); + } + + + public bool ApplySourceToPreview() + { + bool res = true; + + if (previewMaterial == null || sourceMaterial == null) + { + res = false; + } + else + { + previewMaterial.CopyMatchingPropertiesFromMaterial(sourceMaterial); + } + + return res; + } + } + + public class RendererOverride + { + public Renderer renderer; + public MaterialOverride[] materialsOverrides; + + public Material[] sourceMaterials; + public Material[] previewMaterials; + + public RendererOverride(Renderer renderer) + { + this.renderer = renderer; + this.materialsOverrides = new MaterialOverride[renderer.sharedMaterials.Length]; + + sourceMaterials = new Material[materialsOverrides.Length]; + previewMaterials = new Material[materialsOverrides.Length]; + + for (int i = 0; i < materialsOverrides.Length; i++) + { + materialsOverrides[i] = new MaterialOverride(renderer.sharedMaterials[i]); + sourceMaterials[i] = materialsOverrides[i].sourceMaterial; + previewMaterials[i] = materialsOverrides[i].previewMaterial; + } + } + + public void UsePreviewMaterials() + { + if (renderer != null) + { + renderer.sharedMaterials = previewMaterials; + } + } + + public void UseMaterialSource() + { + if (renderer != null) + { + renderer.sharedMaterials = sourceMaterials; + } + } + + public void ApplyPreviewMaterial() + { + for (int i = 0; i < materialsOverrides.Length; i++) + { + materialsOverrides[i].ApplyPreviewToSource(); + renderer.sharedMaterials[i] = materialsOverrides[i].sourceMaterial; + } + } + + public void DiscardChanges() + { + renderer.hideFlags = HideFlags.None; + UseMaterialSource(); + } + + public Material[] GetPreviewMaterials() + { + return previewMaterials; + } + + public void CleanPreviewMaterials() + { + for(int i = 0; i < materialsOverrides.Length; i++) + { + MaterialOverride matOverride = materialsOverrides[i]; + + matOverride.ApplySourceToPreview(); + + string[] keywords = new string[matOverride.sourceMaterial.shaderKeywords.Length]; + matOverride.sourceMaterial.shaderKeywords.CopyTo(keywords, 0); + + matOverride.previewMaterial.shaderKeywords = keywords; + } + } + } + + public enum ApplyTarget + { + CURRENT_SCENE, + SELECTED_FOLDERS, + ALL_PROJECT, + } + + public List effectOverrides; + public List generalPropertiesOverrides; + + public RendererOverride[] rendererOverrides; + + public ApplyTarget applyTarget; + + [SerializeField] private Object[] folders; + + public void Initialize() + { + ResetData(); + } + + public void ResetData() + { + effectOverrides = new List(); + generalPropertiesOverrides = new List(); + + rendererOverrides = new RendererOverride[0]; + applyTarget = ApplyTarget.CURRENT_SCENE; + } + + public void CreateRendererOverride() + { + Renderer[] renderers = FindObjectsByType(FindObjectsSortMode.None); + for (int i = 0; i < renderers.Length; i++) + { + if (renderers[i] is ParticleSystemRenderer) { continue; } + if (renderers[i].sharedMaterial == null) { continue; } + + + renderers[i].hideFlags = HideFlags.NotEditable; + RendererOverride rendererOverride = new RendererOverride(renderers[i]); + ArrayUtility.Add(ref rendererOverrides, rendererOverride); + } + } + + public List CollectAffectedMaterials() + { + List res = new List(); + + switch (applyTarget) + { + case ApplyTarget.SELECTED_FOLDERS: + CollectAffectedMaterialsOnSelectedFolders(res); + break; + case ApplyTarget.CURRENT_SCENE: + CollectAffectedMaterialsOnCurrentScene(res); + break; + case ApplyTarget.ALL_PROJECT: + CollectAffectedMaterialsAllProject(res); + break; + } + + return res; + } + + public void UsePreviewMaterials() + { + for (int i = 0; i < rendererOverrides.Length; i++) + { + rendererOverrides[i].UsePreviewMaterials(); + } + } + + public void UseMaterialSource() + { + for (int i = 0; i < rendererOverrides.Length; i++) + { + rendererOverrides[i].UseMaterialSource(); + } + } + + public void EndOverrideProcess() + { + for (int i = 0; i < rendererOverrides.Length; i++) + { + if (rendererOverrides[i].renderer == null) { continue; } + + rendererOverrides[i].DiscardChanges(); + } + + //for(int i = 0; i < rendererOverrides.Length; i++) + //{ + // rendererOverrides[i].renderer.hideFlags = HideFlags.None; + //} + + //UseMaterialSource(); + + effectOverrides = new List(); + rendererOverrides = new RendererOverride[0]; + } + + public void ApplyChangesToMaterials(Material[] materials) + { + for (int i = 0; i < materials.Length; i++) + { + ApplyChangesToMaterial(materials[i]); + } + } + + public void ApplyChangesToMaterials(List materials) + { + for(int i = 0; i < materials.Count; i++) + { + ApplyChangesToMaterial(materials[i]); + } + } + + public void ApplyChangesToMaterial(Material mat) + { + for (int i = 0; i < effectOverrides.Count; i++) + { + effectOverrides[i].ApplyChangesToMaterial(mat); + } + + for (int i = 0; i < generalPropertiesOverrides.Count; i++) + { + generalPropertiesOverrides[i].ApplyChangesToMaterial(mat); + } + } + + private void CollectAffectedMaterialsOnCurrentScene(List affectedMaterials) + { + for (int i = 0; i < rendererOverrides.Length; i++) + { + affectedMaterials.AddRange(rendererOverrides[i].sourceMaterials); + } + } + + private void CollectAffectedMaterialsOnSelectedFolders(List affectedMaterials) + { + HashSet materialsInFolderGUIDs = new HashSet(); + + for (int i = 0; i < folders.Length; i++) + { + string folderPath = AssetDatabase.GetAssetPath(folders[i]); + if (AssetDatabase.IsValidFolder(folderPath)) + { + string[] assetsPathsInFolder = AssetDatabase.FindAssets("t: Material", new string[] { folderPath }); + + for (int j = 0; j < assetsPathsInFolder.Length; j++) + { + materialsInFolderGUIDs.Add(assetsPathsInFolder[j]); + } + } + } + + foreach (string guid in materialsInFolderGUIDs) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + Material mat = AssetDatabase.LoadAssetAtPath(path); + + if (EditorUtils.IsAllIn13DShader(mat.shader)) + { + affectedMaterials.Add(mat); + } + } + } + + private void CollectAffectedMaterialsAllProject(List affectedMaterials) + { + string[] materialsGUIDs = AssetDatabase.FindAssets("t: Material"); + + foreach (string guid in materialsGUIDs) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + Material mat = AssetDatabase.LoadAssetAtPath(path); + + if (EditorUtils.IsAllIn13DShader(mat.shader)) + { + affectedMaterials.Add(mat); + } + } + } + + public bool IsApplyEnabled() + { + bool res = false; + + switch (applyTarget) + { + case ApplyTarget.SELECTED_FOLDERS: + res = (folders != null) && (folders.Length > 0); + break; + case ApplyTarget.CURRENT_SCENE: + res = true; + break; + case ApplyTarget.ALL_PROJECT: + res = true; + break; + } + + return res; + } + + public AbstractEffectOverride AddEffectOverride(AllIn13DEffectConfig effectConfig) + { + AbstractEffectOverride res = FindEffectOverride(effectConfig.keywordPropertyName); + + if (res == null) + { + switch (effectConfig.effectConfigType) + { + case EffectConfigType.EFFECT_ENUM: + res = new EffectEnumOverride(effectConfig); + break; + case EffectConfigType.EFFECT_TOGGLE: + res = new EffectToggleOverride(effectConfig); + break; + } + + effectOverrides.Add(res); + } + + return res; + } + + public void AddCopmleteEffectOverride(AllIn13DEffectConfig effectConfig, Shader shader) + { + AbstractEffectOverride effectOverride = FindEffectOverride(effectConfig.keywordPropertyName); + + if(effectOverride == null) + { + effectOverride = AddEffectOverride(effectConfig); + } + + for (int i = 0; i < effectConfig.effectProperties.Count; i++) + { + effectOverride.AddPropertyOverride(effectConfig.effectProperties[i], shader); + } + } + + public void AddPropertyOverride(AllIn13DEffectConfig effectConfig, EffectProperty effectProperty, Shader shader) + { + AbstractEffectOverride effectOverride = FindEffectOverride(effectConfig.keywordPropertyName); + + effectOverride = AddEffectOverride(effectConfig); + effectOverride.AddPropertyOverride(effectProperty.propertyIndex, shader); + } + + public void AddGeneralPropertyOverride(int propertyIndex, Shader shader) + { + PropertyOverride propertyOverride = new PropertyOverride(null, propertyIndex, shader); + if (!generalPropertiesOverrides.Contains(propertyOverride)) + { + generalPropertiesOverrides.Add(propertyOverride); + } + } + + public void RemoveEffectOverride(AbstractEffectOverride effectOverrideToRemove) + { + effectOverrides.Remove(effectOverrideToRemove); + + RebuildPreviewMaterial(); + } + + public void RemovePropertyOverride(PropertyOverride propertyOverride) + { + bool removeSuccessfully = propertyOverride.Remove(); + if (!removeSuccessfully) + { + generalPropertiesOverrides.Remove(propertyOverride); + } + } + + public void RebuildPreviewMaterial() + { + for (int i = 0; i < rendererOverrides.Length; i++) + { + rendererOverrides[i].CleanPreviewMaterials(); + } + + ShowPreviewChanges(); + } + + public void ShowPreviewChanges() + { + for (int i = 0; i < rendererOverrides.Length; i++) + { + RendererOverride rendererOverride = rendererOverrides[i]; + + rendererOverride.UsePreviewMaterials(); + + ApplyChangesToMaterials(rendererOverride.previewMaterials); + } + } + + public AbstractEffectOverride FindEffectOverride(string effectPropertyName) + { + AbstractEffectOverride res = null; + + for(int i = 0; i < effectOverrides.Count; i++) + { + if (effectOverrides[i].propertyName == effectPropertyName) + { + res = effectOverrides[i]; + break; + } + } + + return res; + } + + public bool IsEmpty() + { + bool res = effectOverrides.Count <= 0 && generalPropertiesOverrides.Count <= 0; + return res; + } + + public bool DiscardChanges(Renderer[] renderers) + { + bool changes = false; + + for(int i = this.rendererOverrides.Length - 1; i >= 0; i--) + { + for(int j = 0; j < renderers.Length; j++) + { + if (this.rendererOverrides[i].renderer == renderers[j]) + { + rendererOverrides[i].DiscardChanges(); + ArrayUtility.RemoveAt(ref this.rendererOverrides, i); + + changes = true; + + break; + } + } + } + + return changes; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/MaterialOverrideData.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/MaterialOverrideData.cs.meta new file mode 100644 index 0000000..7405e57 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/MaterialOverrideData.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 74623754e448ca3499d27a22fd49f94a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/MaterialOverrideData.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/OverrideEntry.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/OverrideEntry.cs new file mode 100644 index 0000000..d4303d8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/OverrideEntry.cs @@ -0,0 +1,43 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public abstract class OverrideEntry + { + public enum OverrideCategory + { + KEYWORD_TOGGLE, + KEYWORD_ENUM, + COMMON, + GLOBAL_PROPERTY, + } + + public OverrideCategory overrideCategory; + + + public OverrideEntry(OverrideCategory overrideCategory) + { + this.overrideCategory = overrideCategory; + } + + public abstract void ApplyChangesToMaterial(Material mat); + + public override bool Equals(object obj) + { + bool res = false; + + if (obj is OverrideEntry) + { + OverrideEntry overrideEntry = (OverrideEntry)obj; + res = overrideCategory == overrideEntry.overrideCategory; + } + + return res; + } + + public override int GetHashCode() + { + return overrideCategory.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/OverrideEntry.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/OverrideEntry.cs.meta new file mode 100644 index 0000000..270099c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/OverrideEntry.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: e130f397ef034734c995ecaed8cb8d4c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/OverrideEntry.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverride.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverride.cs new file mode 100644 index 0000000..b859ec1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverride.cs @@ -0,0 +1,247 @@ +using UnityEngine; +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + public class PropertyOverride + { + public string propertyName + { + get; private set; + } + + public string displayName + { + get; private set; + } + + private AbstractEffectOverride effectOverride; + + public ShaderPropertyType shaderPropertyType; + public PropertyOverrideType propertyOverrideType; + + public float floatValue; + public int intValue; + public Color colorValue; + public Vector2 rangeLimits; + public Vector4 vectorValue; + public Texture texValue; + public Vector4 tilingAndOffset; + + public bool isHDR; + public bool hasTilingAndOffset; + + public string[] keywords; + + + public PropertyOverride(AbstractEffectOverride effectOverride, int propertyIndex, Shader shader) + { + this.effectOverride = effectOverride; + + string propDescription = shader.GetPropertyName(propertyIndex); + + if(propDescription == "_FogOn") + { + this.propertyOverrideType = PropertyOverrideType.TOGGLE; + this.keywords = new string[1] { "_FOG_ON" }; + } + else + { + this.propertyOverrideType = PropertyOverrideType.BASIC; + this.keywords = new string[0]; + } + + Initialize(propertyIndex, shader); + } + + public PropertyOverride(AbstractEffectOverride effectOverride, EffectProperty effectProperty, Shader shader) + { + this.effectOverride = effectOverride; + + if (effectProperty.IsToggleProperty()) + { + this.propertyOverrideType = PropertyOverrideType.TOGGLE; + } + else if (effectProperty.IsEnumProperty()) + { + this.propertyOverrideType = PropertyOverrideType.ENUM; + } + + if (this.propertyOverrideType != PropertyOverrideType.BASIC) + { + keywords = new string[effectProperty.propertyKeywords.Length]; + for (int i = 0; i < effectProperty.propertyKeywords.Length; i++) + { + keywords[i] = effectProperty.propertyKeywords[i]; + } + } + + this.isHDR = effectProperty.isHDR; + + Initialize(effectProperty, shader); + } + + + private void Initialize(int propertyIndex, Shader shader) + { + string propertyName = shader.GetPropertyName(propertyIndex); + string displayName = shader.GetPropertyDescription(propertyIndex); + + ShaderPropertyType shaderPropertyType = shader.GetPropertyType(propertyIndex); + bool hasTilingAndOffset = + shaderPropertyType == ShaderPropertyType.Texture && !shader.GetPropertyFlags(propertyIndex).HasFlag(ShaderPropertyFlags.NoScaleOffset); + + + Initialize(propertyIndex, propertyName, displayName, shaderPropertyType, hasTilingAndOffset, shader); + + //if (this.shaderPropertyType == ShaderPropertyType.Range) + //{ + // this.rangeLimits = shader.GetPropertyRangeLimits(propertyIndex); + //} + } + + private void Initialize(EffectProperty effectProperty, Shader shader) + { + Initialize(effectProperty.propertyIndex, effectProperty.propertyName, effectProperty.displayName, effectProperty.shaderPropertyType, + effectProperty.hasTilingAndOffset, shader); + + //this.propertyName = shader.GetPropertyName(effectProperty.propertyIndex); + //this.displayName = shader.GetPropertyDescription(effectProperty.propertyIndex); + + //this.shaderPropertyType = shader.GetPropertyType(effectProperty.propertyIndex); + + //if (this.shaderPropertyType == ShaderPropertyType.Range) + //{ + // this.rangeLimits = shader.GetPropertyRangeLimits(effectProperty.propertyIndex); + //} + + //InitializeDefaultValues(effectProperty.propertyIndex, shader); + } + + private void Initialize(int propertyIndex, string propertyName, string displayName, ShaderPropertyType shaderPropertyType, bool hasTilingAndOffset, Shader shader) + { + this.tilingAndOffset = new Vector4(1f, 1f, 0f, 0f); + + this.propertyName = propertyName; + this.displayName = displayName; + this.shaderPropertyType = shaderPropertyType; + this.hasTilingAndOffset = hasTilingAndOffset; + + if(shaderPropertyType == ShaderPropertyType.Range) + { + this.rangeLimits = shader.GetPropertyRangeLimits(propertyIndex); + } + + InitializeDefaultValues(propertyIndex, shader); + } + + private void InitializeDefaultValues(int propertyIndex, Shader shader) + { + switch (shaderPropertyType) + { + case ShaderPropertyType.Range: + case ShaderPropertyType.Float: + this.floatValue = shader.GetPropertyDefaultFloatValue(propertyIndex); + break; + case ShaderPropertyType.Vector: + this.vectorValue = shader.GetPropertyDefaultVectorValue(propertyIndex); + break; + case ShaderPropertyType.Color: + this.colorValue = shader.GetPropertyDefaultVectorValue(propertyIndex); + break; + case ShaderPropertyType.Int: + this.intValue = (int)shader.GetPropertyDefaultFloatValue(propertyIndex); + break; + } + } + + public override bool Equals(object obj) + { + bool res = false; + + if (obj is PropertyOverride) + { + PropertyOverride propertyOverride = (PropertyOverride)obj; + res = (propertyName == propertyOverride.propertyName); + } + + return res; + } + + public override int GetHashCode() + { + int res = propertyName.GetHashCode(); + + return res; + } + + public void ApplyChangesToMaterial(Material mat) + { + if(mat == null) { return; } + + if (this.propertyOverrideType == PropertyOverrideType.ENUM) + { + for(int i = 0; i < keywords.Length; i++) + { + string kw = (propertyName + "_" + keywords[i]).ToUpperInvariant(); + mat.DisableKeyword(kw); + + if(i == floatValue) + { + mat.EnableKeyword(kw); + } + } + } + else if(this.propertyOverrideType == PropertyOverrideType.TOGGLE) + { + string kw = keywords[0]; + + if (floatValue > 0) + { + mat.EnableKeyword(kw); + } + else + { + mat.DisableKeyword(kw); + } + } + + switch (shaderPropertyType) + { + case ShaderPropertyType.Float: + case ShaderPropertyType.Range: + mat.SetFloat(propertyName, floatValue); + break; + case ShaderPropertyType.Color: + mat.SetColor(propertyName, colorValue); + break; + case ShaderPropertyType.Texture: + mat.SetTexture(propertyName, texValue); + if (hasTilingAndOffset) + { + string propST = propertyName + "_ST"; + mat.SetVector(propST, tilingAndOffset); + } + break; + case ShaderPropertyType.Vector: + mat.SetVector(propertyName, vectorValue); + break; + case ShaderPropertyType.Int: + mat.SetInt(propertyName, intValue); + break; + } + } + + public bool Remove() + { + bool res = false; + + if(effectOverride != null) + { + res = effectOverride.RemovePropertyOverride(this); + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverride.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverride.cs.meta new file mode 100644 index 0000000..becfb7a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverride.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 108081ac17dcca346914c1f8627b1b27 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverride.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverrideType.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverrideType.cs new file mode 100644 index 0000000..6f939bb --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverrideType.cs @@ -0,0 +1,9 @@ +namespace AllIn13DShader +{ + public enum PropertyOverrideType + { + BASIC, + TOGGLE, + ENUM, + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverrideType.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverrideType.cs.meta new file mode 100644 index 0000000..2602250 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverrideType.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: b986e4ec738f7004cb7259afd96aef52 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertyOverrideType.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertySelectorAuxWindow.cs b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertySelectorAuxWindow.cs new file mode 100644 index 0000000..907a9ac --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertySelectorAuxWindow.cs @@ -0,0 +1,175 @@ +using System; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class PropertySelectorAuxWindow : EditorWindow + { + public enum SelectionType + { + GLOBAL_PROPERTY, + ADVANCED_PROPERTY, + EFFECT_GROUP, + } + + public enum TypeOfPropertyAdded + { + GLOBAL_PROPERTY, + ADVANCED_PROPERTY, + EFFECT_PROPERTY, + EFFECT_MAIN, + } + + private PropertiesConfigCollection propertiesConfigCollection; + + //private Shader allIn13DShader; + private Shader allIn13DShaderOutline; + + //private PropertiesConfig propertiesConfigNormal; + private PropertiesConfig propertiesConfigOutline; + + private int effectGroupIdx; + private int effectIdx; + private int globalPropertyIdx; + private int advancedPropertyIdx; + + private EffectGroup selectedEffectGroup; + private AllIn13DEffectConfig selectedEffectConfig; + private EffectProperty selectedEffectProperty; + + private TypeOfPropertyAdded typeOfPropertyAdded; + private SelectionType selectionType; + + private Action propertyOverrideAddedCallback; + + private void OnEnable() + { + //this.allIn13DShader = Shader.Find(Constants.SHADER_FULL_NAME_ALLIN13D); + this.allIn13DShaderOutline = Shader.Find(Constants.SHADER_FULL_NAME_ALLIN13D_OUTLINE); + + this.effectIdx = 0; + this.globalPropertyIdx = 0; + this.advancedPropertyIdx = 0; + + propertiesConfigCollection = EditorUtils.FindAsset("PropertiesConfigCollection"); + propertiesConfigOutline = propertiesConfigCollection.FindPropertiesConfigByShader(allIn13DShaderOutline); + } + + public void Setup(Action propertyOverrideAddedCallback) + { + this.propertyOverrideAddedCallback = propertyOverrideAddedCallback; + } + + private void OnGUI() + { + DrawEffectGroupSelector(); + + if(selectionType == SelectionType.EFFECT_GROUP) + { + DrawEffectSelector(); + } + else if(selectionType == SelectionType.GLOBAL_PROPERTY) + { + DrawGlobalPropertySelector(); + } + else if(selectionType == SelectionType.ADVANCED_PROPERTY) + { + DrawAdvancedPropertySelector(); + } + + GUILayout.Space(20f); + + if (GUILayout.Button("Add")) + { + AddProperty(); + } + } + + private void DrawEffectGroupSelector() + { + string[] effectsGroupsNames = propertiesConfigOutline.GetEffectGroupsDisplayNames(); + ArrayUtility.Insert(ref effectsGroupsNames, 0, "Advanced Properties"); + ArrayUtility.Insert(ref effectsGroupsNames, 0, "Global Properties"); + + effectGroupIdx = EditorGUILayout.Popup("Group", effectGroupIdx, effectsGroupsNames); + + if(effectGroupIdx == 0) + { + selectionType = SelectionType.GLOBAL_PROPERTY; + this.selectedEffectGroup = null; + } + else if(effectGroupIdx == 1) + { + selectionType = SelectionType.ADVANCED_PROPERTY; + this.selectedEffectGroup = null; + } + else + { + selectionType = SelectionType.EFFECT_GROUP; + this.selectedEffectGroup = propertiesConfigOutline.effectsGroups[effectGroupIdx - 2]; + } + } + + private void DrawEffectSelector() + { + string[] effectsNames = selectedEffectGroup.GetEffectsNames(); + effectIdx = EditorGUILayout.Popup("Effect", effectIdx, effectsNames); + + selectedEffectConfig = selectedEffectGroup.effects[effectIdx]; + } + + private void DrawGlobalPropertySelector() + { + string[] globalPropertyNames = propertiesConfigOutline.GetGlobalPropertyNames(); + globalPropertyIdx = EditorGUILayout.Popup("Property", globalPropertyIdx, globalPropertyNames); + } + + private void DrawAdvancedPropertySelector() + { + string[] globalPropertyNames = propertiesConfigOutline.GetAdvancedPropertyNames(); + advancedPropertyIdx = EditorGUILayout.Popup("Property", advancedPropertyIdx, globalPropertyNames); + } + + private void AddProperty() + { + if(selectionType == SelectionType.GLOBAL_PROPERTY) + { + typeOfPropertyAdded = TypeOfPropertyAdded.GLOBAL_PROPERTY; + } + else if(selectionType == SelectionType.ADVANCED_PROPERTY) + { + typeOfPropertyAdded = TypeOfPropertyAdded.ADVANCED_PROPERTY; + } + else + { + if(selectedEffectProperty == null) + { + typeOfPropertyAdded = TypeOfPropertyAdded.EFFECT_MAIN; + } + else + { + typeOfPropertyAdded = TypeOfPropertyAdded.EFFECT_PROPERTY; + } + } + + if (propertyOverrideAddedCallback != null) + { + switch (typeOfPropertyAdded) + { + case TypeOfPropertyAdded.GLOBAL_PROPERTY: + propertyOverrideAddedCallback(selectedEffectConfig, propertiesConfigOutline.singleProperties[globalPropertyIdx], allIn13DShaderOutline, typeOfPropertyAdded); + break; + case TypeOfPropertyAdded.ADVANCED_PROPERTY: + propertyOverrideAddedCallback(selectedEffectConfig, propertiesConfigOutline.advancedProperties[advancedPropertyIdx + 1], allIn13DShaderOutline, typeOfPropertyAdded); + break; + case TypeOfPropertyAdded.EFFECT_MAIN: + propertyOverrideAddedCallback(selectedEffectConfig, -1, allIn13DShaderOutline, typeOfPropertyAdded); + break; + } + } + + Close(); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertySelectorAuxWindow.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertySelectorAuxWindow.cs.meta new file mode 100644 index 0000000..e8ee29f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertySelectorAuxWindow.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 135c1998be2528b458ad97784b0692ee +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialOverride/Scripts/PropertySelectorAuxWindow.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets.meta new file mode 100644 index 0000000..552c91d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 815334c2adb929e4496fa20adf7b7eb6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_AllIn13DShaderLook.mat b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_AllIn13DShaderLook.mat new file mode 100644 index 0000000..5207109 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_AllIn13DShaderLook.mat @@ -0,0 +1,377 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: MAT_Preset_AllIn13DShaderLook + m_Shader: {fileID: 4800000, guid: 0dde7f0097aeb2541aea684ca0ad0e3c, type: 3} + m_ValidKeywords: + - _ALBEDOVERTEXCOLORMODE_REPLACE + - _ALPHA_CUTOFF_ON + - _CAST_SHADOWS_ON + - _COLORRAMPLIGHTINGSTAGE_BEFORELIGHTING + - _GREYSCALESTAGE_BEFORELIGHTING + - _HEIGHTGRADIENTPOSITIONSPACE_LOCAL + - _LIGHTMODEL_FAKEGI + - _MATCAPBLENDMODE_MULTIPLY + - _OUTLINETYPE_NONE + - _REFLECTIONS_CLASSIC + - _RIMLIGHTINGSTAGE_BEFORELIGHTINGLAST + - _RIM_LIGHTING_ON + - _SHADINGMODEL_BASIC + - _SPECULARMODEL_CLASSIC + - _TEXTUREBLENDINGMODE_RGB + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + - _TRIPLANARNORMALSPACE_WORLD + m_InvalidKeywords: + - _GLITCHWORLDSPACE_ON + - _HOLOGRAM_ALPHA + - _SPECULAR_ADDITIONAL_LIGHTS + - _VERTEXCOLORBLENDINGMODE_RGB + - _VERTEXCOLORMODE_TEXTUREBLENDING + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _AOMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapB: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapBlack: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapG: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapWhite: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureB: + m_Texture: {fileID: 2800000, guid: f39690d17007ab242928cd91e5a530a6, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureBlack: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureG: + m_Texture: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureWhite: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ColorRampTex: + m_Texture: {fileID: 2800000, guid: 99b6592afee2790429156fef1dc9ba44, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DistortTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _FadeTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MatcapTex: + m_Texture: {fileID: 2800000, guid: cf3a2315564d4de4eb8601b697dea358, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _NormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SSSMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecularMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TexBlendingMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ThicknessMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ToonRamp: + m_Texture: {fileID: 2800000, guid: 339398f75cfa2714d93579662d08ec9a, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TripalanarTopNormalMap: + m_Texture: {fileID: 2800000, guid: 120df76dc2d17ed4cb2d4b8b08292ed9, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TripalanarTopTex: + m_Texture: {fileID: 2800000, guid: a26b9f1a12d33184ab5e89d304e441ad, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TriplanarTopNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TriplanarTopTex: + m_Texture: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _VertexDistortionNoiseTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 6.46, y: 2} + m_Offset: {x: 0, y: 0} + - _VertexExtrudeNoiseTex: + m_Texture: {fileID: 2800000, guid: baea65a7abf3c5a4095956327ddb1122, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AOContrast: 1 + - _AOMapEnabled: 0 + - _AOMapStrength: 1 + - _AdvancedConfigurationEnabled: 0 + - _AffectedByLightmaps: 0 + - _AlbedoVertexColorMode: 1 + - _AlbedoVertexColorOn: 0 + - _AlphaCutoffOn: 1 + - _AlphaCutoffValue: 0.25 + - _AlphaRoundOn: 0 + - _AnisoOffset: -0.2 + - _AnisoShininess: 0.85 + - _Anisotropy: 0.27 + - _BlendDst: 0 + - _BlendSrc: 1 + - _BlendingMaskCutoffB: 0.1 + - _BlendingMaskCutoffG: 0.1 + - _BlendingMaskCutoffWhite: 0.15 + - _BlendingMaskSmoothnessB: 0.4 + - _BlendingMaskSmoothnessG: 0.4 + - _BlendingMaskSmoothnessWhite: 0.4 + - _Brightness: 0 + - _CastShadowsOn: 1 + - _ColorMask: 15 + - _ColorRampBlend: 1 + - _ColorRampLightingStage: 0 + - _ColorRampLuminosity: 0 + - _ColorRampOn: 0 + - _ColorRampScrollSpeed: 0 + - _ColorRampTiling: 1 + - _Contrast: 1 + - _ContrastBrightnessOn: 0 + - _CullingMode: 2 + - _CustomShadowColorOn: 0 + - _DepthColoringOn: 0 + - _DepthGlowColorIntensity: 25 + - _DepthGlowDist: 0.2 + - _DepthGlowGlobalIntensity: 2 + - _DepthGlowPower: 25 + - _DistortAmount: 0.3 + - _DistortTexXSpeed: 2 + - _DistortTexYSpeed: 2 + - _EmissionEnabled: 0 + - _EmissionSelfGlow: 1 + - _ExtrudeBlend: 0.243 + - _FaceDownCutoff: 0.25 + - _FadeAmount: 0 + - _FadeBurnOn: 0 + - _FadeBurnWidth: 0.01 + - _FadeOn: 0 + - _FadePower: 1 + - _FadeTransition: 0.2 + - _FogOn: 0 + - _GeneralAlpha: 1 + - _Glitch: 0 + - _GlitchAmount: 0.5 + - _GlitchSpeed: 2.5 + - _GlitchTiling: 5 + - _GlitchWorldSpace: 1 + - _GreyScaleStage: 0 + - _Greyscale: 0 + - _GreyscaleBlend: 1 + - _GreyscaleLuminosity: 0 + - _HalfLambertWrap: 1 + - _HandDrawn: 0 + - _HandDrawnAmount: 10 + - _HandDrawnSpeed: 5 + - _HardnessFakeGI: 0.72 + - _HeightGradientOn: 0 + - _HeightGradientPositionSpace: 0 + - _HighlightCutoff: 0.5 + - _HighlightSmoothness: 0.5 + - _Highlights: 0 + - _HighlightsStrength: 1 + - _Hightlights: 0 + - _HightlightsStrength: 1 + - _Hit: 0 + - _HitBlend: 1 + - _HitGlow: 5 + - _Hologram: 0 + - _HologramAccentAlpha: 0.5 + - _HologramAccentFrequency: 2 + - _HologramAccentSpeed: 1 + - _HologramAlpha: 1 + - _HologramBaseAlpha: 0.1 + - _HologramFrequency: 20 + - _HologramLineCenter: 0.5 + - _HologramLineSmoothness: 2 + - _HologramLineSpacing: 2 + - _HologramScrollSpeed: 2 + - _HologramSpeed: 0 + - _HueBrightness: 1 + - _HueSaturation: 1 + - _HueShift: 0 + - _HueShiftEnabled: 0 + - _InflateBlend: 1 + - _IntersectionFadeFactor: 1 + - _IntersectionFadeOn: 0 + - _IntersectionGlowOn: 0 + - _LightModel: 5 + - _LineSize: 0 + - _Matcap: 0 + - _MatcapBlend: 1 + - _MatcapBlendMode: 0 + - _MatcapIntensity: 1 + - _MaxCameraDistance: 1000 + - _MaxExtrude: 2 + - _MaxFadeDistance: 250 + - _MaxGradientHeight: 0.75 + - _MaxHologramAlpha: 1 + - _MaxInflate: 0.2 + - _MaxRim: 1 + - _Metallic: 0 + - _MinExtrude: 0 + - _MinGradientHeight: 0 + - _MinHologramAlpha: 0 + - _MinInflate: 0 + - _MinRim: 0.58 + - _NormalInfluence: 0.5 + - _NormalMapEnabled: 0 + - _NormalStrength: 1 + - _NumLines: 10 + - _NumReflectionColors: 5 + - _OutlineMode: 6 + - _OutlineThickness: 28.9 + - _OutlineType: 0 + - _Pixelate: 0 + - _PixelateSize: 32 + - _Posterize: 0 + - _PosterizeGamma: 0.75 + - _PosterizeNumColors: 8 + - _RecalculateNormals: 0 + - _Reflections: 1 + - _ReflectionsAtten: 0.025 + - _RenderPreset: 1 + - _RimAttenuation: 0.1 + - _RimLighting: 1 + - _RimLightingStage: 1 + - _SSSAtten: 1 + - _SSSFrontAtten: 0.3 + - _SSSFrontPower: 3 + - _SSSPower: 1 + - _ScaleWithCameraDistance: 0 + - _ScreenSpaceUVOn: 0 + - _ScrollTextureOn: 0 + - _ScrollTextureScrollX: 1 + - _ScrollTextureScrollY: 1 + - _ScrollTextureX: 1 + - _ScrollTextureY: 1 + - _ShadingModel: 0 + - _ShakeBlend: 1 + - _ShakeSpeedMult: 1 + - _Shininess: 12.8 + - _Smoothness: 0.5 + - _SpecularAdditionalLights: 1 + - _SpecularAtten: 0.6 + - _SpecularModel: 1 + - _SpecularToonCutoff: 0.35 + - _SpecularToonSmoothness: 0 + - _SpherizeNormals: 0 + - _StochasticSampling: 0 + - _StochasticScale: 3.464 + - _StochasticSkew: 0.57735026 + - _SubsurfaceScattering: 0 + - _TextureBlending: 0 + - _TextureBlendingMode: 0 + - _TextureBlendingSource: 0 + - _TimingSeed: 0 + - _ToonColorAttenuation: 0.25 + - _ToonCutoff: 0.5 + - _ToonFactor: 0 + - _ToonSmoothness: 0 + - _TopNormalStrength: 1 + - _TriplanarMappingOn: 0 + - _TriplanarNormalSpace: 1 + - _TriplanarSharpness: 15 + - _UVDistortion: 0 + - _UseCustomTime: 0 + - _VertexColor: 0 + - _VertexColorBlending: 1 + - _VertexColorBlendingMode: 0 + - _VertexColorMode: 0 + - _VertexDistortionAmount: 0 + - _VertexDistortionOn: 0 + - _VertexExtrude: 0 + - _VertexExtrudeNoiseXSpeed: 4 + - _VertexExtrudeNoiseYSpeed: 4 + - _VertexExtrudeUseNoiseTex: 1 + - _VertexInflate: 0 + - _VertexShakeOn: 0 + - _VoxelBlend: 1 + - _VoxelSize: 100 + - _Voxelize: 0 + - _WaveAmount: 7 + - _WaveSpeed: 10 + - _WaveStrength: 7.5 + - _WaveUVOn: 0 + - _WaveX: 0 + - _WaveY: 0.5 + - _ZTestMode: 4 + - _ZWrite: 1 + m_Colors: + - _AOColor: {r: 0, g: 0, b: 0, a: 0} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _DepthGlowColor: {r: 1, g: 0.9869999, b: 0.6, a: 1} + - _EmissionColor: {r: 1, g: 1, b: 1, a: 1} + - _FadeBurnColor: {r: 1, g: 1, b: 0, a: 1} + - _GlitchOffset: {r: -0.5, g: 0, b: 0, a: 0} + - _GradientHeightColor01: {r: 0.2, g: 0.2, b: 0.2, a: 1} + - _GradientHeightColor02: {r: 1, g: 1, b: 1, a: 1} + - _GreyscaleTintColor: {r: 1, g: 1, b: 1, a: 1} + - _HighlightOffset: {r: 0, g: 0, b: 0, a: 0} + - _HighlightsColor: {r: 2, g: 2, b: 2, a: 1} + - _HitColor: {r: 1, g: 1, b: 1, a: 1} + - _HologramColor: {r: 1.25, g: 2.8, b: 6.8, a: 1} + - _HologramLineDirection: {r: 0, g: 1, b: 0, a: 0} + - _RimColor: {r: 1, g: 1, b: 1, a: 1} + - _RimOffset: {r: 0, g: 0.3, b: 0, a: 0} + - _SSSColor: {r: 1, g: 1, b: 1, a: 1} + - _ShakeMaxDisplacement: {r: 0.1, g: 0.1, b: 0.1, a: 0} + - _ShakeSpeed: {r: 41, g: 49, b: 45, a: 0} + - _VertexDistortionNoiseSpeed: {r: 4, g: 4, b: 0, a: 0} + m_BuildTextureStacks: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_AllIn13DShaderLook.mat.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_AllIn13DShaderLook.mat.meta new file mode 100644 index 0000000..8018912 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_AllIn13DShaderLook.mat.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: c47ffb1264d98194ca46e4502b86c74f +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_AllIn13DShaderLook.mat + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Basic.mat b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Basic.mat new file mode 100644 index 0000000..ae5d98d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Basic.mat @@ -0,0 +1,370 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: MAT_Preset_Basic + m_Shader: {fileID: 4800000, guid: 0dde7f0097aeb2541aea684ca0ad0e3c, type: 3} + m_ValidKeywords: + - _ALBEDOVERTEXCOLORMODE_REPLACE + - _ALPHA_CUTOFF_ON + - _CAST_SHADOWS_ON + - _COLORRAMPLIGHTINGSTAGE_AFTERLIGHTING + - _FOG_ON + - _GREYSCALESTAGE_BEFORELIGHTING + - _HEIGHTGRADIENTPOSITIONSPACE_LOCAL + - _LIGHTMODEL_CLASSIC + - _MATCAPBLENDMODE_MULTIPLY + - _OUTLINETYPE_NONE + - _REFLECTIONS_NONE + - _RIMLIGHTINGSTAGE_BEFORELIGHTINGLAST + - _SHADINGMODEL_BASIC + - _SPECULARMODEL_CLASSIC + - _TEXTUREBLENDINGMODE_RGB + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + - _TRIPLANARNORMALSPACE_WORLD + m_InvalidKeywords: + - _GLITCHWORLDSPACE_ON + - _HOLOGRAM_ALPHA + - _REFLECTIONS_BASIC + - _REFLECTIONS_ON + - _REFLECTIONTYPE_NONE + - _SHADING_MODEL_BASIC + - _SPECULAR_ADDITIONAL_LIGHTS + - _VERTEX_EXTRUDE_USE_NOISE_TEX + - _WORKFLOW_BASIC + m_LightmapFlags: 4 + m_EnableInstancingVariants: 1 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _AOMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapB: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapG: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapWhite: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureB: + m_Texture: {fileID: 2800000, guid: f39690d17007ab242928cd91e5a530a6, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureG: + m_Texture: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureWhite: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ColorRampTex: + m_Texture: {fileID: 2800000, guid: 99b6592afee2790429156fef1dc9ba44, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DistortTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 15, y: 15} + m_Offset: {x: 5, y: 5} + - _EmissionMap: + m_Texture: {fileID: 2800000, guid: e8745f0a17582af43aa61e323be9d994, type: 3} + m_Scale: {x: 10, y: 10} + m_Offset: {x: 0, y: 0} + - _FadeTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MatcapTex: + m_Texture: {fileID: 2800000, guid: cf3a2315564d4de4eb8601b697dea358, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _NormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 5, y: 5} + m_Offset: {x: 0, y: 0} + - _SSSMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecularMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TexBlendingMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ThicknessMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ToonRamp: + m_Texture: {fileID: 2800000, guid: 339398f75cfa2714d93579662d08ec9a, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TripalanarTopNormalMap: + m_Texture: {fileID: 2800000, guid: 120df76dc2d17ed4cb2d4b8b08292ed9, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TripalanarTopTex: + m_Texture: {fileID: 2800000, guid: 6ea6651424065304492be443204adf61, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TriplanarTopNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TriplanarTopTex: + m_Texture: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _VertexDistortionNoiseTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _VertexExtrudeNoiseTex: + m_Texture: {fileID: 2800000, guid: baea65a7abf3c5a4095956327ddb1122, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AOContrast: 1 + - _AOMapEnabled: 0 + - _AOMapStrength: 1 + - _AdvancedConfigurationEnabled: 0 + - _AffectedByLightmaps: 0 + - _AlbedoVertexColorMode: 1 + - _AlbedoVertexColorOn: 0 + - _AlphaCutoffOn: 1 + - _AlphaCutoffValue: 0.25 + - _AlphaRoundOn: 0 + - _AnisoOffset: -0.2 + - _AnisoShininess: 0.85 + - _Anisotropy: 0.45 + - _BlendDst: 0 + - _BlendSrc: 1 + - _BlendingMaskCutoffB: 0.1 + - _BlendingMaskCutoffG: 0.1 + - _BlendingMaskCutoffWhite: 0.15 + - _BlendingMaskSmoothnessB: 0.4 + - _BlendingMaskSmoothnessG: 0.4 + - _BlendingMaskSmoothnessWhite: 0.4 + - _Brightness: 0 + - _CastShadowsOn: 1 + - _ColorMask: 15 + - _ColorRampBlend: 1 + - _ColorRampLightingStage: 1 + - _ColorRampLuminosity: 0 + - _ColorRampOn: 0 + - _ColorRampScrollSpeed: 0 + - _ColorRampTiling: 1 + - _Contrast: 1 + - _ContrastBrightnessOn: 0 + - _CullingMode: 2 + - _CustomShadowColorOn: 0 + - _DepthColoringOn: 0 + - _DepthGlowColorIntensity: 25 + - _DepthGlowDist: 0.2 + - _DepthGlowGlobalIntensity: 2 + - _DepthGlowPower: 25 + - _DistortAmount: 0.3 + - _DistortTexXSpeed: 2 + - _DistortTexYSpeed: 2 + - _EmissionEnabled: 0 + - _EmissionSelfGlow: 1 + - _ExtrudeBlend: 0.243 + - _FaceDownCutoff: 0.25 + - _FadeAmount: 0 + - _FadeBurnOn: 0 + - _FadeBurnWidth: 0.01 + - _FadeOn: 0 + - _FadePower: 1 + - _FadeTransition: 0.2 + - _FogOn: 1 + - _GeneralAlpha: 1 + - _Glitch: 0 + - _GlitchAmount: 0.5 + - _GlitchSpeed: 2.5 + - _GlitchTiling: 5 + - _GlitchWorldSpace: 1 + - _GreyScaleStage: 0 + - _Greyscale: 0 + - _GreyscaleBlend: 1 + - _GreyscaleLuminosity: 0 + - _HalfLambertWrap: 0.66 + - _HandDrawn: 0 + - _HandDrawnAmount: 10 + - _HandDrawnSpeed: 5 + - _HardnessFakeGI: 0.734 + - _HeightGradientOn: 0 + - _HeightGradientPositionSpace: 0 + - _HighlightCutoff: 0.5 + - _HighlightSmoothness: 0.5 + - _Highlights: 0 + - _HighlightsStrength: 1 + - _Hightlights: 0 + - _HightlightsStrength: 1 + - _Hit: 0 + - _HitBlend: 1 + - _HitGlow: 5 + - _Hologram: 0 + - _HologramAccentAlpha: 0.5 + - _HologramAccentFrequency: 2 + - _HologramAccentSpeed: 1 + - _HologramAlpha: 1 + - _HologramBaseAlpha: 0.1 + - _HologramFrequency: 20 + - _HologramLineCenter: 0.5 + - _HologramLineSmoothness: 2 + - _HologramLineSpacing: 2 + - _HologramScrollSpeed: 2 + - _HologramSpeed: 81.1 + - _HueBrightness: 1 + - _HueSaturation: 1 + - _HueShift: 0 + - _HueShiftEnabled: 0 + - _InflateBlend: 1 + - _IntersectionFadeFactor: 1 + - _IntersectionFadeOn: 0 + - _IntersectionGlowOn: 0 + - _LightModel: 1 + - _LineSize: 0.298 + - _Matcap: 0 + - _MatcapBlend: 1 + - _MatcapBlendMode: 0 + - _MatcapIntensity: 1 + - _MaxCameraDistance: 1000 + - _MaxExtrude: 2 + - _MaxFadeDistance: 250 + - _MaxGradientHeight: 0.75 + - _MaxHologramAlpha: 1 + - _MaxInflate: 0.2 + - _MaxRim: 1 + - _Metallic: 1 + - _MinExtrude: 0 + - _MinGradientHeight: 0 + - _MinHologramAlpha: 0 + - _MinInflate: 0 + - _MinRim: 0 + - _NormalInfluence: 0.5 + - _NormalMapEnabled: 0 + - _NormalStrength: 1 + - _NumLines: 5 + - _NumReflectionColors: 5 + - _OutlineMode: 6 + - _OutlineThickness: 28.9 + - _OutlineType: 0 + - _Pixelate: 0 + - _PixelateSize: 32 + - _Posterize: 0 + - _PosterizeGamma: 0.75 + - _PosterizeNumColors: 8 + - _RecalculateNormals: 0 + - _Reflections: 0 + - _ReflectionsAtten: 0.5 + - _RenderPreset: 1 + - _RimAttenuation: 1 + - _RimLighting: 0 + - _RimLightingStage: 1 + - _SSSAtten: 1 + - _SSSFrontAtten: 0.3 + - _SSSFrontPower: 3 + - _SSSPower: 1 + - _ScaleWithCameraDistance: 0 + - _ScreenSpaceUVOn: 0 + - _ScrollTextureOn: 0 + - _ScrollTextureScrollX: 1 + - _ScrollTextureScrollY: 1 + - _ScrollTextureX: 1 + - _ScrollTextureY: 1 + - _ShadingModel: 0 + - _ShakeBlend: 1 + - _ShakeSpeedMult: 1 + - _Shininess: 6.5 + - _Smoothness: 1 + - _SpecularAdditionalLights: 1 + - _SpecularAtten: 0.8 + - _SpecularModel: 1 + - _SpecularToonCutoff: 0.836 + - _SpecularToonSmoothness: 0 + - _SpherizeNormals: 0 + - _StochasticSampling: 0 + - _StochasticScale: 3.464 + - _StochasticSkew: 0.57735026 + - _SubsurfaceScattering: 0 + - _TextureBlending: 0 + - _TextureBlendingMode: 0 + - _TextureBlendingSource: 0 + - _TimingSeed: 0 + - _ToonColorAttenuation: 0.25 + - _ToonCutoff: 0.732 + - _ToonFactor: 0 + - _ToonSmoothness: 0.037 + - _TopNormalStrength: 1 + - _TriplanarMappingOn: 0 + - _TriplanarNormalSpace: 1 + - _TriplanarSharpness: 15 + - _UVDistortion: 0 + - _UseCustomTime: 0 + - _VertexColorBlending: 1 + - _VertexDistortionAmount: 0 + - _VertexDistortionOn: 0 + - _VertexExtrude: 0 + - _VertexExtrudeNoiseXSpeed: 4 + - _VertexExtrudeNoiseYSpeed: 4 + - _VertexExtrudeUseNoiseTex: 1 + - _VertexInflate: 0 + - _VertexShakeOn: 0 + - _VoxelBlend: 1 + - _VoxelSize: 100 + - _Voxelize: 0 + - _WaveAmount: 7 + - _WaveSpeed: 10 + - _WaveStrength: 7.5 + - _WaveUVOn: 0 + - _WaveX: 0 + - _WaveY: 0.5 + - _ZTestMode: 4 + - _ZWrite: 1 + m_Colors: + - _AOColor: {r: 0, g: 0, b: 0, a: 0} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _DepthGlowColor: {r: 1, g: 0.9869999, b: 0.6, a: 1} + - _EmissionColor: {r: 1, g: 1, b: 1, a: 1} + - _FadeBurnColor: {r: 2.6701567, g: 0.052356016, b: 0, a: 1} + - _GlitchOffset: {r: -0.5, g: 0, b: 0, a: 0} + - _GradientHeightColor01: {r: 0.2, g: 0.2, b: 0.2, a: 1} + - _GradientHeightColor02: {r: 1, g: 1, b: 1, a: 1} + - _GreyscaleTintColor: {r: 1, g: 1, b: 1, a: 1} + - _HighlightOffset: {r: 0, g: 0, b: 0, a: 0} + - _HighlightsColor: {r: 2, g: 2, b: 2, a: 1} + - _HitColor: {r: 1, g: 1, b: 1, a: 1} + - _HologramColor: {r: 0.35, g: 0.8, b: 2, a: 1} + - _HologramLineDirection: {r: 0, g: 1, b: 0, a: 0} + - _RimColor: {r: 1, g: 1, b: 1, a: 1} + - _RimOffset: {r: 0, g: 0, b: 0, a: 0} + - _SSSColor: {r: 1, g: 1, b: 1, a: 1} + - _ShakeMaxDisplacement: {r: 0.1, g: 0.1, b: 0.1, a: 0} + - _ShakeSpeed: {r: 5, g: 5, b: 5, a: 0} + - _VertexDistortionNoiseSpeed: {r: 4, g: 4, b: 0, a: 0} + m_BuildTextureStacks: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Basic.mat.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Basic.mat.meta new file mode 100644 index 0000000..7964a92 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Basic.mat.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 1df0aef2ca6d85a4b9bb7478096c635a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Basic.mat + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_StandardPBR.mat b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_StandardPBR.mat new file mode 100644 index 0000000..c7fc664 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_StandardPBR.mat @@ -0,0 +1,405 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: MAT_Preset_StandardPBR + m_Shader: {fileID: 4800000, guid: 0dde7f0097aeb2541aea684ca0ad0e3c, type: 3} + m_ValidKeywords: + - _ALPHA_CUTOFF_ON + - _CAST_SHADOWS_ON + - _FOG_ON + - _GREYSCALESTAGE_BEFORELIGHTING + - _LIGHTMODEL_CLASSIC + - _MATCAPBLENDMODE_MULTIPLY + - _OUTLINETYPE_NONE + - _RECEIVE_SHADOWS_ON + - _REFLECTIONS_CLASSIC + - _RIMLIGHTINGSTAGE_BEFORELIGHTINGLAST + - _SHADINGMODEL_PBR + - _SPECULARMODEL_CLASSIC + - _TEXTUREBLENDINGMODE_RGB + - _USE_WIND_VERTICAL_MASK + m_InvalidKeywords: + - _ALBEDOVERTEXCOLORMODE_REPLACE + - _COLORRAMPLIGHTINGSTAGE_AFTERLIGHTING + - _GLITCHWORLDSPACE_ON + - _HEIGHTGRADIENTPOSITIONSPACE_LOCAL + - _HOLOGRAM_ALPHA + - _RECEIVEDSHADOWSTYPE_CLASSIC + - _REFLECTIONS_BASIC + - _REFLECTIONS_ON + - _REFLECTIONTYPE_NONE + - _SHADING_MODEL_PBR + - _SPECULAR_ADDITIONAL_LIGHTS + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + - _TRIPLANARNORMALSPACE_WORLD + - _VERTEX_EXTRUDE_USE_NOISE_TEX + - _WORKFLOW_BASIC + m_LightmapFlags: 4 + m_EnableInstancingVariants: 1 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _AOMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapB: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapG: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapWhite: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureB: + m_Texture: {fileID: 2800000, guid: f39690d17007ab242928cd91e5a530a6, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureG: + m_Texture: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureWhite: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ColorRampTex: + m_Texture: {fileID: 2800000, guid: 99b6592afee2790429156fef1dc9ba44, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DistortTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 15, y: 15} + m_Offset: {x: 5, y: 5} + - _EmissionMap: + m_Texture: {fileID: 2800000, guid: e8745f0a17582af43aa61e323be9d994, type: 3} + m_Scale: {x: 10, y: 10} + m_Offset: {x: 0, y: 0} + - _FadeTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _GlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MatcapTex: + m_Texture: {fileID: 2800000, guid: cf3a2315564d4de4eb8601b697dea358, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _NormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 5, y: 5} + m_Offset: {x: 0, y: 0} + - _SSSMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecularMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TexBlendingMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ThicknessMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ToonRamp: + m_Texture: {fileID: 2800000, guid: 339398f75cfa2714d93579662d08ec9a, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TripalanarTopNormalMap: + m_Texture: {fileID: 2800000, guid: 120df76dc2d17ed4cb2d4b8b08292ed9, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TripalanarTopTex: + m_Texture: {fileID: 2800000, guid: 6ea6651424065304492be443204adf61, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TriplanarTopNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TriplanarTopTex: + m_Texture: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _VertexDistortionNoiseTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _VertexExtrudeNoiseTex: + m_Texture: {fileID: 2800000, guid: baea65a7abf3c5a4095956327ddb1122, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AOContrast: 1 + - _AOMapEnabled: 0 + - _AOMapStrength: 1 + - _AdvancedConfigurationEnabled: 0 + - _AffectedByLightmaps: 0 + - _AlbedoVertexColorMode: 1 + - _AlbedoVertexColorOn: 0 + - _AlphaCutoffOn: 1 + - _AlphaCutoffValue: 0.25 + - _AlphaRoundOn: 0 + - _AnisoOffset: -0.2 + - _AnisoShininess: 0.85 + - _Anisotropy: 0.45 + - _BlendDst: 0 + - _BlendSrc: 1 + - _BlendingMaskCutoffB: 0.1 + - _BlendingMaskCutoffG: 0.1 + - _BlendingMaskCutoffWhite: 0.15 + - _BlendingMaskSmoothnessB: 0.4 + - _BlendingMaskSmoothnessG: 0.4 + - _BlendingMaskSmoothnessWhite: 0.4 + - _Brightness: 0 + - _BrightnessLM: 0 + - _CastShadowsOn: 1 + - _ColorMask: 15 + - _ColorRampBlend: 1 + - _ColorRampLightingStage: 1 + - _ColorRampLuminosity: 0 + - _ColorRampOn: 0 + - _ColorRampScrollSpeed: 0 + - _ColorRampTiling: 1 + - _Contrast: 1 + - _ContrastBrightnessOn: 0 + - _ContrastLM: 1 + - _CullingMode: 2 + - _CustomAmbientLightOn: 0 + - _CustomShadowColorOn: 0 + - _DepthColoringOn: 0 + - _DepthGlowColorIntensity: 25 + - _DepthGlowDist: 0.2 + - _DepthGlowGlobalIntensity: 2 + - _DepthGlowPower: 25 + - _DistortAmount: 0.3 + - _DistortTexXSpeed: 2 + - _DistortTexYSpeed: 2 + - _DitherOn: 0 + - _DitherScale: 1 + - _EmissionEnabled: 0 + - _EmissionSelfGlow: 1 + - _ExtrudeBlend: 0.243 + - _FaceDownCutoff: 0.25 + - _FadeAmount: 0 + - _FadeBurnOn: 0 + - _FadeBurnWidth: 0.01 + - _FadeByCamDistanceOn: 0 + - _FadeOn: 0 + - _FadePower: 1 + - _FadeTransition: 0.2 + - _FogOn: 1 + - _GeneralAlpha: 1 + - _Glitch: 0 + - _GlitchAmount: 0.5 + - _GlitchSpeed: 2.5 + - _GlitchTiling: 5 + - _GlitchWorldSpace: 1 + - _GlossMapOn: 0 + - _GreyScaleStage: 0 + - _Greyscale: 0 + - _GreyscaleBlend: 1 + - _GreyscaleLuminosity: 0 + - _HalfLambertWrap: 0.66 + - _HandDrawn: 0 + - _HandDrawnAmount: 10 + - _HandDrawnSpeed: 5 + - _HardnessFakeGI: 0.734 + - _HeightGradientOn: 0 + - _HeightGradientPositionSpace: 0 + - _HighlightCutoff: 0.5 + - _HighlightSmoothness: 0.5 + - _Highlights: 0 + - _HighlightsStrength: 1 + - _Hightlights: 0 + - _HightlightsStrength: 1 + - _Hit: 0 + - _HitBlend: 1 + - _HitGlow: 5 + - _Hologram: 0 + - _HologramAccentAlpha: 0.5 + - _HologramAccentFrequency: 2 + - _HologramAccentSpeed: 1 + - _HologramAlpha: 1 + - _HologramBaseAlpha: 0.1 + - _HologramFrequency: 20 + - _HologramLineCenter: 0.5 + - _HologramLineSmoothness: 2 + - _HologramLineSpacing: 2 + - _HologramScrollSpeed: 2 + - _HologramSpeed: 81.1 + - _HueBrightness: 1 + - _HueBrightnessLM: 1 + - _HueSaturation: 1 + - _HueSaturationLM: 1 + - _HueShift: 0 + - _HueShiftEnabled: 0 + - _HueShiftLM: 0 + - _InflateBlend: 1 + - _IntersectionFadeFactor: 1 + - _IntersectionFadeOn: 0 + - _IntersectionGlowOn: 0 + - _LightModel: 1 + - _LightmapColorCorrection: 0 + - _LineSize: 0.298 + - _Matcap: 0 + - _MatcapBlend: 1 + - _MatcapBlendMode: 0 + - _MatcapIntensity: 1 + - _MaxCameraDistance: 1000 + - _MaxDistanceToFade: 100 + - _MaxExtrude: 2 + - _MaxFadeDistance: 250 + - _MaxGradientHeight: 0.75 + - _MaxHologramAlpha: 1 + - _MaxInflate: 0.2 + - _MaxRim: 1 + - _Metallic: 0 + - _MetallicMapOn: 0 + - _MinDistanceToFade: 0 + - _MinExtrude: 0 + - _MinGradientHeight: 0 + - _MinHologramAlpha: 0 + - _MinInflate: 0 + - _MinRim: 0 + - _NearFade: 0 + - _NormalInfluence: 0.5 + - _NormalMapEnabled: 0 + - _NormalStrength: 1 + - _NumLines: 5 + - _NumReflectionColors: 5 + - _OutlineMode: 6 + - _OutlineThickness: 28.9 + - _OutlineType: 0 + - _Pixelate: 0 + - _PixelateSize: 32 + - _Posterize: 0 + - _PosterizeGamma: 0.75 + - _PosterizeNumColors: 8 + - _RecalculateNormals: 0 + - _ReceiveShadows: 1 + - _ReceivedShadowsType: 0 + - _Reflections: 1 + - _ReflectionsAtten: 0.5 + - _RenderPreset: 1 + - _RimAttenuation: 1 + - _RimLighting: 0 + - _RimLightingStage: 1 + - _SSSAtten: 1 + - _SSSFrontAtten: 0.3 + - _SSSFrontPower: 3 + - _SSSPower: 1 + - _ScaleWithCameraDistance: 0 + - _ScreenSpaceUVOn: 0 + - _ScrollTextureOn: 0 + - _ScrollTextureScrollX: 1 + - _ScrollTextureScrollY: 1 + - _ScrollTextureX: 1 + - _ScrollTextureY: 1 + - _ShadingModel: 1 + - _ShadowCutoff: 0.2 + - _ShakeBlend: 1 + - _ShakeSpeedMult: 1 + - _Shininess: 6.94 + - _Smoothness: 0.5 + - _SpecularAdditionalLights: 1 + - _SpecularAtten: 1 + - _SpecularModel: 1 + - _SpecularToonCutoff: 0.836 + - _SpecularToonSmoothness: 0 + - _SpherizeNormals: 0 + - _StochasticSampling: 0 + - _StochasticScale: 3.464 + - _StochasticSkew: 0.57735026 + - _SubsurfaceScattering: 0 + - _TextureBlending: 0 + - _TextureBlendingMode: 0 + - _TextureBlendingSource: 0 + - _TimingSeed: 0 + - _ToonColorAttenuation: 0.25 + - _ToonCutoff: 0.732 + - _ToonFactor: 0 + - _ToonSmoothness: 0.037 + - _TopNormalStrength: 1 + - _TriplanarMappingOn: 0 + - _TriplanarNormalSpace: 1 + - _TriplanarSharpness: 15 + - _UVDistortion: 0 + - _UseCustomTime: 0 + - _UseVerticalMask: 1 + - _VertexColorBlending: 1 + - _VertexDistortionAmount: 0 + - _VertexDistortionOn: 0 + - _VertexExtrude: 0 + - _VertexExtrudeNoiseXSpeed: 4 + - _VertexExtrudeNoiseYSpeed: 4 + - _VertexExtrudeUseNoiseTex: 1 + - _VertexInflate: 0 + - _VertexShakeOn: 0 + - _VoxelBlend: 1 + - _VoxelSize: 100 + - _Voxelize: 0 + - _WaveAmount: 7 + - _WaveSpeed: 10 + - _WaveStrength: 7.5 + - _WaveUVOn: 0 + - _WaveX: 0 + - _WaveY: 0.5 + - _WindAttenuation: 1 + - _WindOn: 0 + - _WindVerticalMaskMaxY: 1 + - _WindVerticalMaskMinY: -1 + - _ZTestMode: 4 + - _ZWrite: 1 + m_Colors: + - _AOColor: {r: 0, g: 0, b: 0, a: 0} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _CustomAmbientColor: {r: 0.65, g: 0.65, b: 0.65, a: 1} + - _DepthGlowColor: {r: 1, g: 0.9869999, b: 0.6, a: 1} + - _EmissionColor: {r: 1, g: 1, b: 1, a: 1} + - _FadeBurnColor: {r: 2.6701567, g: 0.052356016, b: 0, a: 1} + - _GlitchOffset: {r: -0.5, g: 0, b: 0, a: 0} + - _GradientHeightColor01: {r: 0.2, g: 0.2, b: 0.2, a: 1} + - _GradientHeightColor02: {r: 1, g: 1, b: 1, a: 1} + - _GreyscaleTintColor: {r: 1, g: 1, b: 1, a: 1} + - _HighlightOffset: {r: 0, g: 0, b: 0, a: 0} + - _HighlightsColor: {r: 2, g: 2, b: 2, a: 1} + - _HitColor: {r: 1, g: 1, b: 1, a: 1} + - _HologramColor: {r: 1.25, g: 2.8, b: 6.8, a: 1} + - _HologramLineDirection: {r: 0, g: 1, b: 0, a: 0} + - _RimColor: {r: 1, g: 1, b: 1, a: 1} + - _RimOffset: {r: 0, g: 0, b: 0, a: 0} + - _SSSColor: {r: 1, g: 1, b: 1, a: 1} + - _ShakeMaxDisplacement: {r: 0.1, g: 0.1, b: 0.1, a: 0} + - _ShakeSpeed: {r: 5, g: 5, b: 5, a: 0} + - _VertexDistortionNoiseSpeed: {r: 4, g: 4, b: 0, a: 0} + m_BuildTextureStacks: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_StandardPBR.mat.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_StandardPBR.mat.meta new file mode 100644 index 0000000..de59808 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_StandardPBR.mat.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: fed1698affe6c124c8eece7c36b256f0 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_StandardPBR.mat + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Toon.mat b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Toon.mat new file mode 100644 index 0000000..57fff96 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Toon.mat @@ -0,0 +1,370 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: MAT_Preset_Toon + m_Shader: {fileID: 4800000, guid: 0dde7f0097aeb2541aea684ca0ad0e3c, type: 3} + m_ValidKeywords: + - _ALBEDOVERTEXCOLORMODE_REPLACE + - _ALPHA_CUTOFF_ON + - _CAST_SHADOWS_ON + - _COLORRAMPLIGHTINGSTAGE_AFTERLIGHTING + - _FOG_ON + - _GREYSCALESTAGE_BEFORELIGHTING + - _HEIGHTGRADIENTPOSITIONSPACE_LOCAL + - _LIGHTMODEL_TOON + - _MATCAPBLENDMODE_MULTIPLY + - _OUTLINETYPE_NONE + - _REFLECTIONS_NONE + - _RIMLIGHTINGSTAGE_BEFORELIGHTINGLAST + - _SHADINGMODEL_BASIC + - _SPECULARMODEL_TOON + - _TEXTUREBLENDINGMODE_RGB + - _TEXTUREBLENDINGSOURCE_VERTEXCOLOR + - _TRIPLANARNORMALSPACE_WORLD + m_InvalidKeywords: + - _GLITCHWORLDSPACE_ON + - _HOLOGRAM_ALPHA + - _REFLECTIONS_BASIC + - _REFLECTIONS_ON + - _REFLECTIONTYPE_NONE + - _SHADING_MODEL_BASIC + - _SPECULAR_ADDITIONAL_LIGHTS + - _VERTEX_EXTRUDE_USE_NOISE_TEX + - _WORKFLOW_BASIC + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _AOMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapB: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapG: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingNormalMapWhite: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureB: + m_Texture: {fileID: 2800000, guid: f39690d17007ab242928cd91e5a530a6, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureG: + m_Texture: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BlendingTextureWhite: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ColorRampTex: + m_Texture: {fileID: 2800000, guid: 99b6592afee2790429156fef1dc9ba44, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DistortTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 15, y: 15} + m_Offset: {x: 5, y: 5} + - _EmissionMap: + m_Texture: {fileID: 2800000, guid: e8745f0a17582af43aa61e323be9d994, type: 3} + m_Scale: {x: 10, y: 10} + m_Offset: {x: 0, y: 0} + - _FadeTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MatcapTex: + m_Texture: {fileID: 2800000, guid: cf3a2315564d4de4eb8601b697dea358, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _NormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 5, y: 5} + m_Offset: {x: 0, y: 0} + - _SSSMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecularMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TexBlendingMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ThicknessMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ToonRamp: + m_Texture: {fileID: 2800000, guid: 339398f75cfa2714d93579662d08ec9a, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TripalanarTopNormalMap: + m_Texture: {fileID: 2800000, guid: 120df76dc2d17ed4cb2d4b8b08292ed9, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TripalanarTopTex: + m_Texture: {fileID: 2800000, guid: 6ea6651424065304492be443204adf61, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TriplanarTopNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _TriplanarTopTex: + m_Texture: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _VertexDistortionNoiseTex: + m_Texture: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _VertexExtrudeNoiseTex: + m_Texture: {fileID: 2800000, guid: baea65a7abf3c5a4095956327ddb1122, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AOContrast: 1 + - _AOMapEnabled: 0 + - _AOMapStrength: 1 + - _AdvancedConfigurationEnabled: 0 + - _AffectedByLightmaps: 0 + - _AlbedoVertexColorMode: 1 + - _AlbedoVertexColorOn: 0 + - _AlphaCutoffOn: 1 + - _AlphaCutoffValue: 0.25 + - _AlphaRoundOn: 0 + - _AnisoOffset: -0.2 + - _AnisoShininess: 0.85 + - _Anisotropy: 0.45 + - _BlendDst: 0 + - _BlendSrc: 1 + - _BlendingMaskCutoffB: 0.1 + - _BlendingMaskCutoffG: 0.1 + - _BlendingMaskCutoffWhite: 0.15 + - _BlendingMaskSmoothnessB: 0.4 + - _BlendingMaskSmoothnessG: 0.4 + - _BlendingMaskSmoothnessWhite: 0.4 + - _Brightness: 0 + - _CastShadowsOn: 1 + - _ColorMask: 15 + - _ColorRampBlend: 1 + - _ColorRampLightingStage: 1 + - _ColorRampLuminosity: 0 + - _ColorRampOn: 0 + - _ColorRampScrollSpeed: 0 + - _ColorRampTiling: 1 + - _Contrast: 1 + - _ContrastBrightnessOn: 0 + - _CullingMode: 2 + - _CustomShadowColorOn: 0 + - _DepthColoringOn: 0 + - _DepthGlowColorIntensity: 25 + - _DepthGlowDist: 0.2 + - _DepthGlowGlobalIntensity: 2 + - _DepthGlowPower: 25 + - _DistortAmount: 0.3 + - _DistortTexXSpeed: 2 + - _DistortTexYSpeed: 2 + - _EmissionEnabled: 0 + - _EmissionSelfGlow: 1 + - _ExtrudeBlend: 0.243 + - _FaceDownCutoff: 0.25 + - _FadeAmount: 0 + - _FadeBurnOn: 0 + - _FadeBurnWidth: 0.01 + - _FadeOn: 0 + - _FadePower: 1 + - _FadeTransition: 0.2 + - _FogOn: 1 + - _GeneralAlpha: 1 + - _Glitch: 0 + - _GlitchAmount: 0.5 + - _GlitchSpeed: 2.5 + - _GlitchTiling: 5 + - _GlitchWorldSpace: 1 + - _GreyScaleStage: 0 + - _Greyscale: 0 + - _GreyscaleBlend: 1 + - _GreyscaleLuminosity: 0 + - _HalfLambertWrap: 0.66 + - _HandDrawn: 0 + - _HandDrawnAmount: 10 + - _HandDrawnSpeed: 5 + - _HardnessFakeGI: 0.734 + - _HeightGradientOn: 0 + - _HeightGradientPositionSpace: 0 + - _HighlightCutoff: 0.5 + - _HighlightSmoothness: 0.5 + - _Highlights: 0 + - _HighlightsStrength: 1 + - _Hightlights: 0 + - _HightlightsStrength: 1 + - _Hit: 0 + - _HitBlend: 1 + - _HitGlow: 5 + - _Hologram: 0 + - _HologramAccentAlpha: 0.5 + - _HologramAccentFrequency: 2 + - _HologramAccentSpeed: 1 + - _HologramAlpha: 1 + - _HologramBaseAlpha: 0.1 + - _HologramFrequency: 20 + - _HologramLineCenter: 0.5 + - _HologramLineSmoothness: 2 + - _HologramLineSpacing: 2 + - _HologramScrollSpeed: 2 + - _HologramSpeed: 81.1 + - _HueBrightness: 1 + - _HueSaturation: 1 + - _HueShift: 0 + - _HueShiftEnabled: 0 + - _InflateBlend: 1 + - _IntersectionFadeFactor: 1 + - _IntersectionFadeOn: 0 + - _IntersectionGlowOn: 0 + - _LightModel: 2 + - _LineSize: 0.298 + - _Matcap: 0 + - _MatcapBlend: 1 + - _MatcapBlendMode: 0 + - _MatcapIntensity: 1 + - _MaxCameraDistance: 1000 + - _MaxExtrude: 2 + - _MaxFadeDistance: 250 + - _MaxGradientHeight: 0.75 + - _MaxHologramAlpha: 1 + - _MaxInflate: 0.2 + - _MaxRim: 1 + - _Metallic: 1 + - _MinExtrude: 0 + - _MinGradientHeight: 0 + - _MinHologramAlpha: 0 + - _MinInflate: 0 + - _MinRim: 0 + - _NormalInfluence: 0.5 + - _NormalMapEnabled: 0 + - _NormalStrength: 1 + - _NumLines: 5 + - _NumReflectionColors: 5 + - _OutlineMode: 6 + - _OutlineThickness: 28.9 + - _OutlineType: 0 + - _Pixelate: 0 + - _PixelateSize: 32 + - _Posterize: 0 + - _PosterizeGamma: 0.75 + - _PosterizeNumColors: 8 + - _RecalculateNormals: 0 + - _Reflections: 0 + - _ReflectionsAtten: 0.641 + - _RenderPreset: 1 + - _RimAttenuation: 1 + - _RimLighting: 0 + - _RimLightingStage: 1 + - _SSSAtten: 1 + - _SSSFrontAtten: 0.3 + - _SSSFrontPower: 3 + - _SSSPower: 1 + - _ScaleWithCameraDistance: 0 + - _ScreenSpaceUVOn: 0 + - _ScrollTextureOn: 0 + - _ScrollTextureScrollX: 1 + - _ScrollTextureScrollY: 1 + - _ScrollTextureX: 1 + - _ScrollTextureY: 1 + - _ShadingModel: 0 + - _ShakeBlend: 1 + - _ShakeSpeedMult: 1 + - _Shininess: 3 + - _Smoothness: 1 + - _SpecularAdditionalLights: 1 + - _SpecularAtten: 1 + - _SpecularModel: 2 + - _SpecularToonCutoff: 0.7 + - _SpecularToonSmoothness: 0 + - _SpherizeNormals: 0 + - _StochasticSampling: 0 + - _StochasticScale: 3.464 + - _StochasticSkew: 0.57735026 + - _SubsurfaceScattering: 0 + - _TextureBlending: 0 + - _TextureBlendingMode: 0 + - _TextureBlendingSource: 0 + - _TimingSeed: 0 + - _ToonColorAttenuation: 0.25 + - _ToonCutoff: 0.5 + - _ToonFactor: 0 + - _ToonSmoothness: 0 + - _TopNormalStrength: 1 + - _TriplanarMappingOn: 0 + - _TriplanarNormalSpace: 1 + - _TriplanarSharpness: 15 + - _UVDistortion: 0 + - _UseCustomTime: 0 + - _VertexColorBlending: 1 + - _VertexDistortionAmount: 0 + - _VertexDistortionOn: 0 + - _VertexExtrude: 0 + - _VertexExtrudeNoiseXSpeed: 4 + - _VertexExtrudeNoiseYSpeed: 4 + - _VertexExtrudeUseNoiseTex: 1 + - _VertexInflate: 0 + - _VertexShakeOn: 0 + - _VoxelBlend: 1 + - _VoxelSize: 100 + - _Voxelize: 0 + - _WaveAmount: 7 + - _WaveSpeed: 10 + - _WaveStrength: 7.5 + - _WaveUVOn: 0 + - _WaveX: 0 + - _WaveY: 0.5 + - _ZTestMode: 4 + - _ZWrite: 1 + m_Colors: + - _AOColor: {r: 0, g: 0, b: 0, a: 0} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _DepthGlowColor: {r: 1, g: 0.9869999, b: 0.6, a: 1} + - _EmissionColor: {r: 1, g: 1, b: 1, a: 1} + - _FadeBurnColor: {r: 2.6701567, g: 0.052356016, b: 0, a: 1} + - _GlitchOffset: {r: -0.5, g: 0, b: 0, a: 0} + - _GradientHeightColor01: {r: 0.2, g: 0.2, b: 0.2, a: 1} + - _GradientHeightColor02: {r: 1, g: 1, b: 1, a: 1} + - _GreyscaleTintColor: {r: 1, g: 1, b: 1, a: 1} + - _HighlightOffset: {r: 0, g: 0, b: 0, a: 0} + - _HighlightsColor: {r: 2, g: 2, b: 2, a: 1} + - _HitColor: {r: 1, g: 1, b: 1, a: 1} + - _HologramColor: {r: 0.35, g: 0.8, b: 2, a: 1} + - _HologramLineDirection: {r: 0, g: 1, b: 0, a: 0} + - _RimColor: {r: 1, g: 1, b: 1, a: 1} + - _RimOffset: {r: 0, g: 0, b: 0, a: 0} + - _SSSColor: {r: 1, g: 1, b: 1, a: 1} + - _ShakeMaxDisplacement: {r: 0.1, g: 0.1, b: 0.1, a: 0} + - _ShakeSpeed: {r: 5, g: 5, b: 5, a: 0} + - _VertexDistortionNoiseSpeed: {r: 4, g: 4, b: 0, a: 0} + m_BuildTextureStacks: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Toon.mat.meta b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Toon.mat.meta new file mode 100644 index 0000000..c88928c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Toon.mat.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: deae43ec6cafe38498ce343202e24586 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/MaterialPresets/MAT_Preset_Toon.mat + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets.meta b/Assets/Plugins/AllIn13DShader/Editor/Presets.meta new file mode 100644 index 0000000..c4ce97b --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f5313e553a160cc49933bc4a2a7df5ca +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingModeCollection.asset b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingModeCollection.asset new file mode 100644 index 0000000..a186d3f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingModeCollection.asset @@ -0,0 +1,18 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4629d07b23a824a409376d81eaa9733c, type: 3} + m_Name: BlendingModeCollection + m_EditorClassIdentifier: + presets: + - {fileID: 11400000, guid: 943e2fa1925ddb449a82703de72fe5d6, type: 2} + - {fileID: 11400000, guid: 97fbadbf86e6b1e429fd63e24df2f76b, type: 2} + - {fileID: 11400000, guid: 9262e4149365ae345b36846643e83a1a, type: 2} diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingModeCollection.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingModeCollection.asset.meta new file mode 100644 index 0000000..f3b15b7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingModeCollection.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: dce34994118e36043b0989f2f4da89b7 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingModeCollection.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Additive.asset b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Additive.asset new file mode 100644 index 0000000..c3fe128 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Additive.asset @@ -0,0 +1,21 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b20560ae87df6542bbfbc050c039189, type: 3} + m_Name: BlendingMode_Additive + m_EditorClassIdentifier: + displayName: Additive + renderQueue: 3000 + blendSrc: 1 + blendDst: 1 + depthWrite: 0 + isTransparent: 1 + defaultEnabledEffects: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Additive.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Additive.asset.meta new file mode 100644 index 0000000..5d7912e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Additive.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 943e2fa1925ddb449a82703de72fe5d6 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Additive.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Opaque.asset b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Opaque.asset new file mode 100644 index 0000000..6c1b72c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Opaque.asset @@ -0,0 +1,21 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b20560ae87df6542bbfbc050c039189, type: 3} + m_Name: BlendingMode_Opaque + m_EditorClassIdentifier: + displayName: Opaque + renderQueue: 2000 + blendSrc: 1 + blendDst: 0 + depthWrite: 1 + defaultEnabledEffects: + - ALPHA_CUTOFF diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Opaque.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Opaque.asset.meta new file mode 100644 index 0000000..03efc2d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Opaque.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 97fbadbf86e6b1e429fd63e24df2f76b +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Opaque.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Transparent.asset b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Transparent.asset new file mode 100644 index 0000000..d79ba00 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Transparent.asset @@ -0,0 +1,21 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b20560ae87df6542bbfbc050c039189, type: 3} + m_Name: BlendingMode_Transparent + m_EditorClassIdentifier: + displayName: Transparent + renderQueue: 3000 + blendSrc: 5 + blendDst: 10 + depthWrite: 0 + isTransparent: 1 + defaultEnabledEffects: [] diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Transparent.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Transparent.asset.meta new file mode 100644 index 0000000..264b458 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Transparent.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 9262e4149365ae345b36846643e83a1a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Presets/BlendingMode_Transparent.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts.meta b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts.meta new file mode 100644 index 0000000..5daae31 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 171c4edd18ab28f44af265dac29fc360 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/BlendingMode.cs b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/BlendingMode.cs new file mode 100644 index 0000000..39978fc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/BlendingMode.cs @@ -0,0 +1,19 @@ +using UnityEngine; +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + public class BlendingMode : ScriptableObject + { + public string displayName; + + public RenderQueue renderQueue; + public UnityEngine.Rendering.BlendMode blendSrc; + public UnityEngine.Rendering.BlendMode blendDst; + public bool depthWrite; + + public bool isTransparent; + + public string[] defaultEnabledEffects; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/BlendingMode.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/BlendingMode.cs.meta new file mode 100644 index 0000000..2330bb2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/BlendingMode.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 6b20560ae87df6542bbfbc050c039189 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/BlendingMode.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPresetCollection.cs b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPresetCollection.cs new file mode 100644 index 0000000..b19033b --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPresetCollection.cs @@ -0,0 +1,42 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class MaterialPresetCollection : ScriptableObject + { + public BlendingMode this[int key] + { + get => presets[key]; + } + + public BlendingMode[] presets; + + public string[] CreateStringsArray() + { + string[] res = new string[presets.Length]; + + for(int i = 0; i < presets.Length; i++) + { + res[i] = presets[i].displayName; + } + + return res; + } + + public int GetIndex(BlendingMode materialPreset) + { + int res = -1; + + for(int i = 0; i < presets.Length; i++) + { + if (presets[i] == materialPreset) + { + res = i; + break; + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPresetCollection.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPresetCollection.cs.meta new file mode 100644 index 0000000..68f8e85 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPresetCollection.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 4629d07b23a824a409376d81eaa9733c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPresetCollection.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPropertyValue.cs b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPropertyValue.cs new file mode 100644 index 0000000..08cc95e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPropertyValue.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [System.Serializable] + public class MaterialPropertyValue + { + public enum ValueType + { + NONE, + INT, + FLOAT, + COLOR, + TEXTURE, + } + + public string propertyName; + + public ValueType valueType; + + public int intValue; + public float floatValue; + public Color colorValue; + public Texture2D textureValue; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPropertyValue.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPropertyValue.cs.meta new file mode 100644 index 0000000..533bac8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPropertyValue.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 86890d6861f68c54181bbbfffcbd8d33 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Presets/Scripts/MaterialPropertyValue.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfig.cs b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfig.cs new file mode 100644 index 0000000..f1d56a3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfig.cs @@ -0,0 +1,441 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using UnityEditor; +using UnityEngine; +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + [System.Serializable] + public class PropertiesConfig + { + public Shader shader; + + public EffectGroup[] effectsGroups; + public List singleProperties; + public List advancedProperties; + + public int renderPreset; + public int blendSrcIdx; + public int blendDstIdx; + public int zWriteIndex; + + public void CreateConfig(EffectGroupGlobalConfigCollection effectGroupGlobalConfigCollection, EffectsExtraData effectsExtraData) + { + effectsGroups = new EffectGroup[0]; + singleProperties = new List(); + advancedProperties = new List(); + + CreateGroups(effectGroupGlobalConfigCollection); + + int numProperties = shader.GetPropertyCount(); + int effectIndex = 0; + for (int i = 0; i < numProperties; i++) + { + string[] attributes = shader.GetPropertyAttributes(i); + string displayName = shader.GetPropertyDescription(i); + string propertyName = shader.GetPropertyName(i); + ShaderPropertyFlags shaderPropertyFlags = shader.GetPropertyFlags(i); + ShaderPropertyType shaderPropertyType = shader.GetPropertyType(i); + + if (propertyName == Constants.MATPROPERTY_RENDERING_MODE) + { + this.renderPreset = i; + } + else + { + if (attributes.Length > 0) + { + int idxOffset = 0; + string firstAttribute = attributes[0]; + string secondAttribute = string.Empty; + if(attributes.Length >= 2) + { + secondAttribute = attributes[1]; + } + + if (firstAttribute.Contains(Constants.EFFECT_ATTRIBUTE_PREFIX)) + { + ConfigureEffect(displayName, i, propertyName, firstAttribute, attributes[idxOffset + 1], effectsExtraData, effectIndex + 1); + } + else if (firstAttribute.StartsWith(Constants.EFFECT_PROPERTY_ATTRIBUTE_PREFIX)) + { + EffectPropertyAttributeData effectPropertyAttributeData = GetEffectPropertyAttributeData(firstAttribute, secondAttribute); + ConfigureProperty(effectPropertyAttributeData, i, propertyName, displayName, shaderPropertyType, shaderPropertyFlags); + } + else if (firstAttribute.Contains(Constants.SINGLE_PROPERTY_ATTRIBUTE)) + { + singleProperties.Add(i); + } + else if (firstAttribute.Contains(Constants.ADVANCED_PROPERTY_ATTRIBUTE)) + { + advancedProperties.Add(i); + } + } + } + + if (propertyName == Constants.MATPROPERTY_BLEND_SRC) + { + this.blendSrcIdx = i; + } + else if (propertyName == Constants.MATPROPERTY_BLEND_DST) + { + this.blendDstIdx = i; + } + } + + RefreshDisplayIndices(); + + zWriteIndex = FindPropertyIndex("_ZWrite"); + } + + private void RefreshDisplayIndices() + { + int effectDisplayIndex = 0; + for (int i = 0; i < effectsGroups.Length; i++) + { + for (int j = 0; j < effectsGroups[i].effects.Length; j++) + { + effectsGroups[i].effects[j].displayIndex = effectDisplayIndex + 1; + effectDisplayIndex++; + } + } + } + + private void CreateGroups(EffectGroupGlobalConfigCollection effectGroupGlobalConfigCollection) + { + for (int i = 0; i < effectGroupGlobalConfigCollection.effectGroupGlobalConfigs.Length; i++) + { + EffectGroupGlobalConfig effectGroupGlobalConfig = effectGroupGlobalConfigCollection.effectGroupGlobalConfigs[i]; + //string groupID = Constants.EFFECTS_GROUPS_IDS[i]; + + EffectGroup group = new EffectGroup(effectGroupGlobalConfig); + ArrayUtility.Add(ref effectsGroups, group); + } + } + + private EffectPropertyAttributeData GetEffectPropertyAttributeData(string attribute, string secondAttribute) + { + EffectPropertyAttributeData res = new EffectPropertyAttributeData(); + + MatchCollection matchCollection = Regex.Matches(attribute, Constants.REGEX_EFFECT_PROOPERTY_COMPLETE); + if (matchCollection != null && matchCollection.Count > 0) + { + res.parentEffectID = matchCollection[0].Groups[1].Value; + string[] keywordListSplit = matchCollection[0].Groups[4].Value.Split(","); + for(int i = 0; i < keywordListSplit.Length; i++) + { + string kw = keywordListSplit[i].Trim(); + res.AddKeyword(kw); + } + + string[] incompatibleKwsSplit = matchCollection[0].Groups[3].Value.Split(","); + for(int i = 0; i < incompatibleKwsSplit.Length; i++) + { + string incompatibleKw = incompatibleKwsSplit[i]; + res.AddIncompatibleKeyword(incompatibleKw); + } + + string strAllowReset = matchCollection[0].Groups[5].Value.ToUpperInvariant(); + res.allowReset = strAllowReset == "TRUE"; + + string strKeywordsOp = matchCollection[0].Groups[2].Value.ToUpperInvariant(); + if (!string.IsNullOrEmpty(strKeywordsOp)) + { + res.keywordsOp = strKeywordsOp == "AND" ? KeywordsOp.AND : KeywordsOp.OR; + } + } + else + { + matchCollection = Regex.Matches(attribute, Constants.REGEX_EFFECT_PROPERTY); + + string[] contentSplit = matchCollection[0].Groups[1].Value.Split(","); + + string parentEffectID = contentSplit[0].Trim(); + res.parentEffectID = parentEffectID; + + if (contentSplit.Length > 1) + { + for (int i = 1; i < contentSplit.Length; i++) + { + string kw = $"_{parentEffectID}_{contentSplit[i].Trim()}"; + res.AddKeyword(kw); + } + } + else + { + string kw = $"_{parentEffectID}_ON"; + res.AddKeyword(kw); + } + } + + if (!string.IsNullOrEmpty(secondAttribute)) + { + matchCollection = Regex.Matches(secondAttribute, Constants.REGEX_KEYWORDS_ENUM); + MatchCollection matchCollectionToggle = Regex.Matches(secondAttribute, Constants.REGEX_TOGGLE); + if (matchCollection.Count >= 1) + { + string[] contentSplit = matchCollection[0].Groups[1].Value.Split(","); + res.AddPropertyKeywords(contentSplit); + } + else if(matchCollectionToggle.Count >= 1) + { + res.AddPropertyKeyword(matchCollectionToggle[0].Groups[1].Value); + } + } + + return res; + } + + private EffectKeywordData[] GetParentEffectKeywords(string attribute, string effectName) + { + MatchCollection matchCollection = Regex.Matches(attribute, Constants.REGEX_PARENT_EFFECT_KEYWORDS); + string[] matchSplitted = matchCollection[0].Groups[1].Value.Split(","); + EffectKeywordData[] res = new EffectKeywordData[matchSplitted.Length]; + for (int i = 0; i < matchSplitted.Length; i++) + { + matchSplitted[i] = matchSplitted[i].Trim(); + + string displayName = matchSplitted[i]; + + string keyword = string.Empty; + if(matchSplitted.Length == 1) + { + keyword = $"{matchSplitted[i].ToUpperInvariant()}"; + } + else + { + keyword = $"_{effectName}_{matchSplitted[i].ToUpperInvariant()}"; + } + + res[i] = new EffectKeywordData(keyword, displayName); + //matchSplitted[i] = matchSplitted[i].ToUpper(); + } + + return res; + } + + private EffectAttributeData GetEffectAttributeData(string rawAttribute) + { + EffectAttributeData res = new EffectAttributeData(); + res.Init(); + + Match match = Regex.Match(rawAttribute, Constants.REGEX_EFFECT); + res.effectID = match.Groups[1].Value.Trim(); + res.groupID = match.Groups[2].Value.Trim(); + res.dependentEffectID = match.Groups[4].Value.Trim(); + res.incompatibleWithEffectID = match.Groups[5].Value.Trim(); + res.docEnabled = match.Groups[6].Value.Trim().ToUpperInvariant() == "TRUE"; + res.drawerID = match.Groups[7].Value.Trim(); + + string extraPassesRaw = match.Groups[8].Value.Trim(); + if (!string.IsNullOrEmpty(extraPassesRaw)) + { + string[] extraPassesSplitted = extraPassesRaw.Split(",", System.StringSplitOptions.RemoveEmptyEntries); + + for(int i = 0; i < extraPassesSplitted.Length; i++) + { + ArrayUtility.Add(ref res.extraPasses, extraPassesSplitted[i].Trim()); + } + } + + if (string.IsNullOrEmpty(res.drawerID)) + { + res.drawerID = Constants.GENERAL_EFFECT_DRAWER_ID; + } + + return res; + } + + private void ConfigureEffect(string displayName, int propertyIndex, string propertyName, string rawEffectAttribute, string attributeKeywords, + EffectsExtraData effectsExtraData, int displayIndex) + { + EffectAttributeData effectAttributeData = GetEffectAttributeData(rawEffectAttribute); + + string effectName = effectAttributeData.effectID; + + AllIn13DEffectConfig effectConfig = FindEffectConfigByID(effectAttributeData.effectID); + EffectKeywordData[] keywordsDatas = GetParentEffectKeywords(attributeKeywords, effectName); + + EffectConfigType effectConfigType = keywordsDatas.Length == 1 ? EffectConfigType.EFFECT_TOGGLE : EffectConfigType.EFFECT_ENUM; + if (effectConfig == null) + { + effectConfig = new AllIn13DEffectConfig(displayName, propertyName, propertyIndex, effectConfigType, + effectAttributeData, effectsExtraData, displayIndex); + + effectConfig.AddKeywords(keywordsDatas); + effectConfig.Setup(); + + EffectGroup effectGroup = GetEffecGroupByID(effectAttributeData.groupID); + effectGroup.AddEffect(effectConfig); + } + } + + private EffectGroup GetEffecGroupByID(string groupID) + { + EffectGroup res = null; + + for (int i = 0; i < effectsGroups.Length; i++) + { + if (effectsGroups[i].GroupID == groupID) + { + res = effectsGroups[i]; + break; + } + } + + return res; + } + + //private void ConfigureProperty(string[] propertyContent, int propertyIndex, string propertyName) + //{ + // string effectID = propertyContent[0]; + // List keywords = new List(); + + // if (propertyContent.Length > 1) + // { + // for (int i = 1; i < propertyContent.Length; i++) + // { + // string kw = $"_{effectID}_{propertyContent[i]}"; + // keywords.Add(kw); + // } + // } + // else + // { + // string kw = $"_{effectID}_ON"; + // keywords.Add(kw); + // } + + // ConfigureProperty(effectID, keywords, propertyIndex, propertyName); + //} + + private void ConfigureProperty(EffectPropertyAttributeData data, int propertyIndex, string propertyName, string displayName, + ShaderPropertyType shaderPropertyType, ShaderPropertyFlags shaderPropertyFlags) + { + AllIn13DEffectConfig effectConfig = FindEffectConfigByID(data.parentEffectID); + EffectProperty effectProperty = effectConfig.CreateEffectProperty(propertyIndex, propertyName, displayName, shaderPropertyType, shaderPropertyFlags, data); + } + + public AllIn13DEffectConfig FindEffectConfigByID(string effectID) + { + AllIn13DEffectConfig res = null; + + for (int groupIdx = 0; groupIdx < effectsGroups.Length; groupIdx++) + { + EffectGroup effectGroup = effectsGroups[groupIdx]; + + res = effectGroup.FindEffectByID(effectID); + + if (res != null) + { + break; + } + } + + return res; + } + + public EffectProperty FindEffectProperty(string effectID, string propertyName) + { + AllIn13DEffectConfig effectConfig = FindEffectConfigByID(effectID); + + EffectProperty res = effectConfig.FindEffectPropertyByName(propertyName); + return res; + } + + public int FindPropertyIndex(string propertyName) + { + int res = shader.FindPropertyIndex(propertyName); + return res; + } + + //public EffectProperty FindGeneralEffectProperty(string propertyName) + //{ + // EffectProperty res = null; + + // for(int i = 0; i < singleProperties.Count; i++) + // { + // break; + // } + + // return res; + //} + + public List GetAllEffects() + { + List res = new List(); + + for (int groupIdx = 0; groupIdx < effectsGroups.Length; groupIdx++) + { + res.AddRange(effectsGroups[groupIdx].effects); + } + + return res; + } + + public EffectGroup FindEffectGroupByID(string groupID) + { + EffectGroup res = null; + + for(int i = 0; i < effectsGroups.Length; i++) + { + if (effectsGroups[i].GroupID == groupID) + { + res = effectsGroups[i]; + break; + } + } + + return res; + } + + public string[] GetEffectGroupsIDs() + { + string[] res = new string[effectsGroups.Length]; + + for(int i = 0; i < effectsGroups.Length; i++) + { + res[i] = effectsGroups[i].GroupID; + } + + return res; + } + + public string[] GetEffectGroupsDisplayNames() + { + string[] res = new string[effectsGroups.Length]; + + for(int i = 0; i < effectsGroups.Length; i++) + { + res[i] = effectsGroups[i].DisplayName; + } + + return res; + } + + public string[] GetGlobalPropertyNames() + { + string[] res = new string[singleProperties.Count]; + + for(int i = 0; i < singleProperties.Count; i++) + { + res[i] = shader.GetPropertyDescription(singleProperties[i]); + } + + return res; + } + + public string[] GetAdvancedPropertyNames() + { + string[] res = new string[advancedProperties.Count - 1]; + + for (int i = 1; i < advancedProperties.Count; i++) + { + res[i - 1] = shader.GetPropertyDescription(advancedProperties[i]); + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfig.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfig.cs.meta new file mode 100644 index 0000000..5ffcb94 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfig.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 6e68af35905cddc49a168dd54443e2c8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/PropertiesConfig.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCollection.cs b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCollection.cs new file mode 100644 index 0000000..5ea92ca --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCollection.cs @@ -0,0 +1,33 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class PropertiesConfigCollection : ScriptableObject + { + public PropertiesConfig propertiesConfig; + + public void AddConfig(PropertiesConfig config) + { + this.propertiesConfig = config; + } + + public PropertiesConfig FindPropertiesConfigByShader(Shader shader) + { + PropertiesConfig res = null; + + res = propertiesConfig; + + return res; + } + + public bool IsAllIn3DShaderMaterial(Material mat) + { + bool res = false; + + res = mat.shader.name.Contains("AllIn13DShader"); + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCollection.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCollection.cs.meta new file mode 100644 index 0000000..5169525 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCollection.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: de2c732907004674f91e71073a09d404 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCollection.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCreator.cs b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCreator.cs new file mode 100644 index 0000000..f23538f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCreator.cs @@ -0,0 +1,139 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class PropertiesConfigCreator + { + private const string KEY_PROPERTIES_CONFIG_CREATED_FIRST_TIME = "AllIn13DShader_PropertiesConfigCreatedFirstTime"; + + private const string ASSET_NAME = "PropertiesConfigCollection.asset"; + + private static PropertiesConfigCollection propertiesCollection; + + private static EffectGroupGlobalConfigCollection effectGroupGlobalConfigCollection; + private static EffectsExtraData effectsExtraData; + + + public static PropertiesConfigCollection CreateConfig() + { + propertiesCollection = CreatePropertiesCollection(); + effectGroupGlobalConfigCollection = GetEffectGroupGlobalConfigCollection(); + effectsExtraData = GetEffectsExtraData(); + + CreatePropertiesConfig(propertiesCollection, Constants.SHADER_NAME_ALLIN13D_OUTLINE); + + EditorUtility.SetDirty(propertiesCollection); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); + + Debug.LogWarning("Creating data..."); + + return propertiesCollection; + } + + private static PropertiesConfigCollection CreatePropertiesCollection() + { + PropertiesConfigCollection res = FindPropertiesCollection(); + string path = AssetDatabase.GetAssetPath(res); + + if (!File.Exists(path)) + { + string propertiesCollectionPath = Path.Combine(GlobalConfiguration.instance.GlobalConfigFolderPath, ASSET_NAME); + res = ScriptableObject.CreateInstance(); + AssetDatabase.CreateAsset(res, propertiesCollectionPath); + AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); + } + + return res; + } + + private static EffectGroupGlobalConfigCollection GetEffectGroupGlobalConfigCollection() + { + string[] guids = AssetDatabase.FindAssets("t:EffectGroupGlobalConfigCollection"); + string path = AssetDatabase.GUIDToAssetPath(guids[0]); + + EffectGroupGlobalConfigCollection res = AssetDatabase.LoadAssetAtPath(path); + return res; + } + + private static EffectsExtraData GetEffectsExtraData() + { + EffectsExtraData res = null; + + res = EditorUtils.FindAsset("EffectsExtraData"); + + return res; + } + + private static void CreatePropertiesConfig(PropertiesConfigCollection propertiesCollection, string shaderName) + { + string shaderNameWithExtension = shaderName + ".shader"; + string assetPath = Path.Combine(Constants.SHADERS_GENERIC_FOLDER_PATH, shaderNameWithExtension); + + Shader shader = AssetDatabase.LoadAssetAtPath(assetPath); + + PropertiesConfig propertiesConfig = new PropertiesConfig(); + propertiesConfig.shader = shader; + + propertiesConfig.CreateConfig(effectGroupGlobalConfigCollection, effectsExtraData); + + propertiesCollection.AddConfig(propertiesConfig); + } + + public static PropertiesConfigCollection FindPropertiesCollection() + { + PropertiesConfigCollection res = null; + + string[] guids = AssetDatabase.FindAssets("t:PropertiesConfigCollection"); + if (guids.Length > 0) + { + string assetPath = AssetDatabase.GUIDToAssetPath(guids[0]); + res = AssetDatabase.LoadAssetAtPath(assetPath); + } + + return res; + } + + public static PropertiesConfigCollection InitIfNeeded(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload) + { + PropertiesConfigCollection res = FindPropertiesCollection(); + + bool assetDeleted = false; + assetDeleted = EditorUtils.ConstainsFileName(deletedAssets, ASSET_NAME); + + bool configCreatedFirstTime = SessionState.GetBool(KEY_PROPERTIES_CONFIG_CREATED_FIRST_TIME, false); + + if (!configCreatedFirstTime) + { +#if UNITY_WEBGL + URPSettingsController.DisableFeature("ALLIN1_DOTS_INSTANCING_SUPPORT"); +#endif + } + +#if !ALLIN13DSHADER_DEVELOP + configCreatedFirstTime = true; +#endif + + bool shadersDeleted = EditorUtils.ContainsAnyFolowingFileNames(deletedAssets, Constants.SHADERS_NAMES, "shader"); + bool shadersImported = false; + if (!shadersDeleted) + { + shadersImported = EditorUtils.ContainsAnyFolowingFileNames(importedAssets, Constants.SHADERS_NAMES, "shader"); + } + + if (res == null || !configCreatedFirstTime || assetDeleted || shadersDeleted /*|| shadersImported*/) + { + SessionState.SetBool(KEY_PROPERTIES_CONFIG_CREATED_FIRST_TIME, true); + ShadersCreatorTool.BuildShaderFiles(); + res = CreateConfig(); + } + + + SessionState.SetBool(KEY_PROPERTIES_CONFIG_CREATED_FIRST_TIME, true); + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCreator.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCreator.cs.meta new file mode 100644 index 0000000..3d061f1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCreator.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 4220235a1363ffa45a709aa2921ab167 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/PropertiesConfigCreator.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/RenderPreset.cs b/Assets/Plugins/AllIn13DShader/Editor/RenderPreset.cs new file mode 100644 index 0000000..84f001a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/RenderPreset.cs @@ -0,0 +1,9 @@ +namespace AllIn13DShader +{ + public enum RenderPreset + { + Transparent = 0, + Additive = 1, + Opaque = 2, + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/RenderPreset.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/RenderPreset.cs.meta new file mode 100644 index 0000000..308c0a2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/RenderPreset.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 2cccc54d5414b39479eba144f916afd6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/RenderPreset.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator.meta new file mode 100644 index 0000000..7b47616 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 84f6ce0d86e52194db40dbecf306268e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Allin13DPassType.cs b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Allin13DPassType.cs new file mode 100644 index 0000000..b7abedc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Allin13DPassType.cs @@ -0,0 +1,14 @@ +namespace AllIn13DShader +{ + public enum AllIn13DPassType + { + NONE = -1, + MAIN = 0, + OUTLINE = 1, + SHADOW_CASTER = 2, + DEPTH_ONLY = 3, + DEPTH_NORMALS = 4, + META = 5, + FORWARD_ADD = 6, + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Allin13DPassType.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Allin13DPassType.cs.meta new file mode 100644 index 0000000..b735153 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Allin13DPassType.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 01bc2741ce1ec4c4fa451accd2525fd3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Allin13DPassType.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/BlendCommand.cs b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/BlendCommand.cs new file mode 100644 index 0000000..baef2cd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/BlendCommand.cs @@ -0,0 +1,32 @@ +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + [System.Serializable] + public class BlendCommand : ShaderCommand + { + private const string SHADER_ENTRY_FORMAT = @"Blend {0}"; + public const string SRC_DEFINED_IN_PROPERTIES = @"[_BlendSrc]"; + public const string DST_DEFINED_IN_PROPERTIES = @"[_BlendDst]"; + + public BlendMode srcBlending = BlendMode.Zero; + public BlendMode dstBlending = BlendMode.One; + + protected override string GetShaderEntryFormat() + { + return SHADER_ENTRY_FORMAT; + } + + protected override string GetShaderEntryValueDefinedInProperties() + { + string res = $"{SRC_DEFINED_IN_PROPERTIES} {DST_DEFINED_IN_PROPERTIES}"; + return res; + } + + protected override string GetShaderEntryValueDefinedInCode() + { + string res = $"{srcBlending.ToString()} {dstBlending.ToString()}"; + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/BlendCommand.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/BlendCommand.cs.meta new file mode 100644 index 0000000..f343727 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/BlendCommand.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 89a6cc3ecd3c6ba4a9fddf82f2c4d643 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/BlendCommand.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ColorMaskCommand.cs b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ColorMaskCommand.cs new file mode 100644 index 0000000..0d6eb4c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ColorMaskCommand.cs @@ -0,0 +1,54 @@ +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + [System.Serializable] + public class ColorMaskCommand : ShaderCommand + { + private const string SHADER_ENTRY_FORMAT = @"ColorMask {0}"; + private const string STR_DEFINED_IN_PROPERTIES = @"[_ColorMask]"; + + public ColorWriteMask colorWriteMask; + + protected override string GetShaderEntryFormat() + { + return SHADER_ENTRY_FORMAT; + } + + protected override string GetShaderEntryValueDefinedInCode() + { + string res = string.Empty; + if (colorWriteMask.HasFlag(ColorWriteMask.Red)) + { + res += "R"; + } + + if (colorWriteMask.HasFlag(ColorWriteMask.Green)) + { + res += "G"; + } + + if (colorWriteMask.HasFlag(ColorWriteMask.Blue)) + { + res += "B"; + } + + if (colorWriteMask.HasFlag(ColorWriteMask.Alpha)) + { + res += "A"; + } + + if (string.IsNullOrEmpty(res)) + { + res = "0"; + } + + return res; + } + + protected override string GetShaderEntryValueDefinedInProperties() + { + return STR_DEFINED_IN_PROPERTIES; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ColorMaskCommand.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ColorMaskCommand.cs.meta new file mode 100644 index 0000000..73ae7f3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ColorMaskCommand.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 5757ab12f7f268a44a4cc0c229b48c33 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ColorMaskCommand.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/CullCommand.cs b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/CullCommand.cs new file mode 100644 index 0000000..b357eaa --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/CullCommand.cs @@ -0,0 +1,29 @@ +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + [System.Serializable] + public class CullCommand : ShaderCommand + { + private const string SHADER_ENTRY_FORMAT = @"Cull {0}"; + private const string STR_DEFINED_IN_PROPERTIES = @"[_CullingMode]"; + + public CullMode cullMode; + + protected override string GetShaderEntryFormat() + { + return SHADER_ENTRY_FORMAT; + } + + protected override string GetShaderEntryValueDefinedInCode() + { + string res = cullMode.ToString(); + return res; + } + + protected override string GetShaderEntryValueDefinedInProperties() + { + return STR_DEFINED_IN_PROPERTIES; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/CullCommand.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/CullCommand.cs.meta new file mode 100644 index 0000000..06ac4c4 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/CullCommand.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 9abdb070dea10dc4b8864fa179806d77 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/CullCommand.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes.meta new file mode 100644 index 0000000..0c9d432 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5d5a3268f1162cb44859fa63b91129fc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPassCollection.asset b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPassCollection.asset new file mode 100644 index 0000000..db57c50 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPassCollection.asset @@ -0,0 +1,21 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a88ccc1bdfb7ccb4788b6169f0e66225, type: 3} + m_Name: ShaderPassCollection + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.ShaderPassCollection + mainPass: {fileID: 11400000, guid: a6c4bacf92f616e46b85269e8937d62e, type: 2} + outlinePass: {fileID: 11400000, guid: d9c53fb10098f244daafa27d2a34f6f1, type: 2} + shadowCasterPass: {fileID: 11400000, guid: cde35f88efc3915459308ded0813329c, type: 2} + depthOnlyPass: {fileID: 11400000, guid: 9c2d274c9d2cd92409f03df624fcc618, type: 2} + depthNormalsPass: {fileID: 11400000, guid: 9c0a77d626be93448a5f98ecd9139d5e, type: 2} + metaPass: {fileID: 11400000, guid: 225f11d6c5bca9e469fcc219041d7cc5, type: 2} + forwardAdd: {fileID: 11400000, guid: 1734ded193e10df49966d25f3bd36a26, type: 2} diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPassCollection.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPassCollection.asset.meta new file mode 100644 index 0000000..6aa0a7a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPassCollection.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 02697d53e5a592b43b0b78710cd1fd60 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPassCollection.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthNormals.asset b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthNormals.asset new file mode 100644 index 0000000..60a6291 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthNormals.asset @@ -0,0 +1,38 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f0d35b40778f5ef47a14fca4766c770a, type: 3} + m_Name: ShaderPass_DepthNormals + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.ShaderPassConfig + passType: 4 + passNameURP: DepthNormals + passNameBIRP: + lightModeTagURP: DepthNormals + lightModeTagBIRP: + passSymbol: ALLIN1_DEPTH_NORMALS_PASS + vertexProgramName: DepthNormalsVertex + fragmentProgramName: DepthNormalsFragment + blendCommand: + shaderCommandValue: 0 + srcBlending: 0 + dstBlending: 0 + cullCommand: + shaderCommandValue: 2 + cullMode: 0 + zWriteCommand: + shaderCommandValue: 1 + zWriteOn: 1 + zTestCommand: + shaderCommandValue: 0 + zTestMode: 4 + colorMaskCommand: + shaderCommandValue: 0 + colorWriteMask: 8 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthNormals.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthNormals.asset.meta new file mode 100644 index 0000000..c1851fd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthNormals.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 9c0a77d626be93448a5f98ecd9139d5e +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthNormals.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthOnly.asset b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthOnly.asset new file mode 100644 index 0000000..010bed1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthOnly.asset @@ -0,0 +1,39 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f0d35b40778f5ef47a14fca4766c770a, type: 3} + m_Name: ShaderPass_DepthOnly + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.ShaderPassConfig + passType: 3 + passName: DepthOnly + passNameURP: DepthOnly + passNameBIRP: + lightModeTagURP: DepthOnly + lightModeTagBIRP: + passSymbol: ALLIN1_DEPTH_ONLY_PASS + vertexProgramName: DepthOnlyVertex + fragmentProgramName: DepthOnlyFragment + blendCommand: + shaderCommandValue: 0 + srcBlending: 0 + dstBlending: 0 + cullCommand: + shaderCommandValue: 2 + cullMode: 0 + zWriteCommand: + shaderCommandValue: 1 + zWriteOn: 1 + zTestCommand: + shaderCommandValue: 0 + zTestMode: 4 + colorMaskCommand: + shaderCommandValue: 1 + colorWriteMask: 8 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthOnly.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthOnly.asset.meta new file mode 100644 index 0000000..ad79fe9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthOnly.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 9c2d274c9d2cd92409f03df624fcc618 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_DepthOnly.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ForwardAdd.asset b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ForwardAdd.asset new file mode 100644 index 0000000..13df393 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ForwardAdd.asset @@ -0,0 +1,41 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f0d35b40778f5ef47a14fca4766c770a, type: 3} + m_Name: ShaderPass_ForwardAdd + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.ShaderPassConfig + passType: 6 + passNameURP: + passNameBIRP: FORWARD_DELTA + lightModeTagURP: + lightModeTagBIRP: ForwardAdd + passSymbol: FORWARD_ADD_PASS + vertexProgramName: BasicVertex + fragmentProgramName: BasicFragmentAdd + blendCommand: + shaderCommandValue: 1 + srcBlending: 1 + dstBlending: 1 + cullCommand: + shaderCommandValue: 2 + cullMode: 0 + zWriteCommand: + shaderCommandValue: 1 + zWriteOn: 0 + zTestCommand: + shaderCommandValue: 1 + zTestMode: 4 + colorMaskCommand: + shaderCommandValue: 0 + colorWriteMask: 0 + extraPragmaLinesBIRP: "#pragma multi_compile_fwdadd_fullshadows\r\n#pragma multi_compile_fog\r\n#pragma + multi_compile_instancing\r\n#pragma multi_compile _ DOTS_INSTANCING_ON\r" + extraPragmaLinesURP: diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ForwardAdd.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ForwardAdd.asset.meta new file mode 100644 index 0000000..dbb63af --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ForwardAdd.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 1734ded193e10df49966d25f3bd36a26 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ForwardAdd.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Main.asset b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Main.asset new file mode 100644 index 0000000..8de8abc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Main.asset @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f0d35b40778f5ef47a14fca4766c770a, type: 3} + m_Name: ShaderPass_Main + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.ShaderPassConfig + passType: 0 + passNameURP: AllIn13D_MainPass_URP + passNameBIRP: AllIn13D_Forward_BIRP + lightModeTagURP: UniversalForward + lightModeTagBIRP: ForwardBase + passSymbol: ALLIN1_FORWARD_PASS + vertexProgramName: BasicVertex + fragmentProgramName: BasicFragment + blendCommand: + shaderCommandValue: 2 + srcBlending: 0 + dstBlending: 0 + cullCommand: + shaderCommandValue: 2 + cullMode: 0 + zWriteCommand: + shaderCommandValue: 2 + zWriteOn: 0 + zTestCommand: + shaderCommandValue: 2 + zTestMode: 0 + colorMaskCommand: + shaderCommandValue: 2 + colorWriteMask: 0 + extraPragmaLinesBIRP: '#pragma multi_compile_fwdbase + + #pragma multi_compile_fog + + #pragma + multi_compile_instancing + + #pragma multi_compile _ DOTS_INSTANCING_ON' + extraPragmaLinesURP: diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Main.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Main.asset.meta new file mode 100644 index 0000000..7c61e9a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Main.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: a6c4bacf92f616e46b85269e8937d62e +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Main.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Meta.asset b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Meta.asset new file mode 100644 index 0000000..43ff71c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Meta.asset @@ -0,0 +1,39 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f0d35b40778f5ef47a14fca4766c770a, type: 3} + m_Name: ShaderPass_Meta + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.ShaderPassConfig + passType: 5 + passName: Meta + passNameURP: Meta + passNameBIRP: + lightModeTagURP: Meta + lightModeTagBIRP: + passSymbol: META_PASS + vertexProgramName: AllIn1VertexMeta + fragmentProgramName: AllIn1FragmentMeta + blendCommand: + shaderCommandValue: 0 + srcBlending: 0 + dstBlending: 0 + cullCommand: + shaderCommandValue: 1 + cullMode: 0 + zWriteCommand: + shaderCommandValue: 0 + zWriteOn: 0 + zTestCommand: + shaderCommandValue: 0 + zTestMode: 4 + colorMaskCommand: + shaderCommandValue: 0 + colorWriteMask: 0 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Meta.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Meta.asset.meta new file mode 100644 index 0000000..ea92671 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Meta.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 225f11d6c5bca9e469fcc219041d7cc5 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Meta.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Outline.asset b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Outline.asset new file mode 100644 index 0000000..026cf46 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Outline.asset @@ -0,0 +1,41 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f0d35b40778f5ef47a14fca4766c770a, type: 3} + m_Name: ShaderPass_Outline + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.ShaderPassConfig + passType: 1 + passNameURP: AllIn13D_Outline_URP + passNameBIRP: AllIn13D_Outline + lightModeTagURP: OutlinePass + lightModeTagBIRP: + passSymbol: ALLIN1_OUTLINE_PASS + vertexProgramName: OutlinePass_Vertex + fragmentProgramName: OutlinePass_Fragment + blendCommand: + shaderCommandValue: 2 + srcBlending: 0 + dstBlending: 0 + cullCommand: + shaderCommandValue: 1 + cullMode: 1 + zWriteCommand: + shaderCommandValue: 0 + zWriteOn: 0 + zTestCommand: + shaderCommandValue: 0 + zTestMode: 0 + colorMaskCommand: + shaderCommandValue: 0 + colorWriteMask: 0 + extraPragmaLinesBIRP: "#pragma multi_compile_instancing\r\n#pragma multi_compile_fog\r\n#pragma + multi_compile _ DOTS_INSTANCING_ON\r" + extraPragmaLinesURP: diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Outline.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Outline.asset.meta new file mode 100644 index 0000000..14a4d68 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Outline.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: d9c53fb10098f244daafa27d2a34f6f1 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_Outline.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ShadowCaster.asset b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ShadowCaster.asset new file mode 100644 index 0000000..31dd804 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ShadowCaster.asset @@ -0,0 +1,41 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f0d35b40778f5ef47a14fca4766c770a, type: 3} + m_Name: ShaderPass_ShadowCaster + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.ShaderPassConfig + passType: 2 + passNameURP: AllIn13D_ShadowCaster_URP + passNameBIRP: AllIn13D_ShadowCaster + lightModeTagURP: ShadowCaster + lightModeTagBIRP: ShadowCaster + passSymbol: SHADOW_CASTER_PASS + vertexProgramName: BasicVertexShadowCaster + fragmentProgramName: BasicFragmentShadowCaster + blendCommand: + shaderCommandValue: 0 + srcBlending: 0 + dstBlending: 0 + cullCommand: + shaderCommandValue: 2 + cullMode: 1 + zWriteCommand: + shaderCommandValue: 1 + zWriteOn: 1 + zTestCommand: + shaderCommandValue: 1 + zTestMode: 4 + colorMaskCommand: + shaderCommandValue: 1 + colorWriteMask: 0 + extraPragmaLinesBIRP: "#pragma multi_compile_instancing\r\n#pragma multi_compile_shadowcaster\r\n#pragma + multi_compile _ DOTS_INSTANCING_ON\r" + extraPragmaLinesURP: diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ShadowCaster.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ShadowCaster.asset.meta new file mode 100644 index 0000000..a895de3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ShadowCaster.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: cde35f88efc3915459308ded0813329c +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/Shader Passes/ShaderPass_ShadowCaster.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommand.cs b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommand.cs new file mode 100644 index 0000000..b3b5043 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommand.cs @@ -0,0 +1,38 @@ +namespace AllIn13DShader +{ + public abstract class ShaderCommand + { + public ShaderCommandValue shaderCommandValue; + + public string GetShaderEntry() + { + string res = string.Empty; + string shaderEntryValue = string.Empty; + + switch (shaderCommandValue) + { + case ShaderCommandValue.DEFINED_IN_CODE: + shaderEntryValue = GetShaderEntryValueDefinedInCode(); + break; + case ShaderCommandValue.DEFINED_IN_PROPERTIES: + shaderEntryValue = GetShaderEntryValueDefinedInProperties(); + break; + } + + if (!string.IsNullOrEmpty(shaderEntryValue)) + { + string format = GetShaderEntryFormat(); + res = string.Format(format, shaderEntryValue); + } + + return res; + } + + protected abstract string GetShaderEntryFormat(); + + protected abstract string GetShaderEntryValueDefinedInProperties(); + + protected abstract string GetShaderEntryValueDefinedInCode(); + + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommand.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommand.cs.meta new file mode 100644 index 0000000..c8d6022 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommand.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 37bf42a5bee9d604ba009aafc01f6ad3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommand.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommandValue.cs b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommandValue.cs new file mode 100644 index 0000000..5eb10ed --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommandValue.cs @@ -0,0 +1,9 @@ +namespace AllIn13DShader +{ + public enum ShaderCommandValue + { + DEFAULT = 0, + DEFINED_IN_CODE = 1, + DEFINED_IN_PROPERTIES = 2, + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommandValue.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommandValue.cs.meta new file mode 100644 index 0000000..6fa73c7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommandValue.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: fe27806e63ec1bd48a18efbdb9c344ca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderCommandValue.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassCollection.cs b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassCollection.cs new file mode 100644 index 0000000..483438d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassCollection.cs @@ -0,0 +1,48 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [CreateAssetMenu(menuName = "AllIn13DShader/Shader Pass Collection")] + public class ShaderPassCollection : ScriptableObject + { + public ShaderPassConfig mainPass; + public ShaderPassConfig outlinePass; + public ShaderPassConfig shadowCasterPass; + public ShaderPassConfig depthOnlyPass; + public ShaderPassConfig depthNormalsPass; + public ShaderPassConfig metaPass; + public ShaderPassConfig forwardAdd; + + public ShaderPassConfig GetShaderPassConfig(AllIn13DPassType passType) + { + ShaderPassConfig res = null; + + switch (passType) + { + case AllIn13DPassType.MAIN: + res = mainPass; + break; + case AllIn13DPassType.OUTLINE: + res = outlinePass; + break; + case AllIn13DPassType.SHADOW_CASTER: + res = shadowCasterPass; + break; + case AllIn13DPassType.DEPTH_ONLY: + res = depthOnlyPass; + break; + case AllIn13DPassType.DEPTH_NORMALS: + res = depthNormalsPass; + break; + case AllIn13DPassType.META: + res = metaPass; + break; + case AllIn13DPassType.FORWARD_ADD: + res = forwardAdd; + break; + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassCollection.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassCollection.cs.meta new file mode 100644 index 0000000..9803423 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassCollection.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: a88ccc1bdfb7ccb4788b6169f0e66225 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassCollection.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassConfig.cs b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassConfig.cs new file mode 100644 index 0000000..afbadb4 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassConfig.cs @@ -0,0 +1,385 @@ +using System; +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +namespace AllIn13DShader +{ + [CreateAssetMenu(menuName = "AllIn13DShader/Shader Pass Config")] + public class ShaderPassConfig : ScriptableObject + { + private const string STENCIL_BLOCK_OUTLINE = @" + Stencil + { + Ref [_StencilRef] + Comp [_OutlineMode] + }"; + + private const string STENCIL_BLOCK_MAIN_PASS = @" + Stencil + { + Ref [_StencilRef] + Comp Always + Pass Replace + }"; + + private const string URP_PASS_SYMBOL = "URP_PASS"; + private const string BIRP_PASS_SYMBOL = "BIRP_PASS"; + + + private const string EFFECT_LIBRARY_PATH_FORMAT = @"Shaders/ShaderLibrary/{0}.hlsl"; + private const string INCLUDE_SHADER_ENTRY_FORMAT = @"#include ""{0}"""; + private const string INCLUDE_WITH_PRAGMA_SHADER_ENTRY_FORMAT = @"#include_with_pragmas ""{0}"""; + private const string DEFINE_SHADER_ENTRY_FORMAT = @"#define {0}"; + private const string LIGHT_MODE_ENTRY_FORMAT = @"""LightMode""=""{0}"""; + + public AllIn13DPassType passType; + + [Header("Pass Name")] + public string passNameURP; + public string passNameBIRP; + + [Header("Light Mode")] + public string lightModeTagURP; + public string lightModeTagBIRP; + + [Header("Pass Symbol")] + public string passSymbol; + + [Header("Vertex/Fragment Program")] + public string vertexProgramName; + public string fragmentProgramName; + + [Header("Command")] + public BlendCommand blendCommand; + public CullCommand cullCommand; + public ZWriteCommand zWriteCommand; + public ZTestCommand zTestCommand; + public ColorMaskCommand colorMaskCommand; + + [Header("Extra Pragma - BIRP")] + [TextArea]public string extraPragmaLinesBIRP; + + [Header("Extra Pragma - URP")] + [TextArea] public string extraPragmaLinesURP; + + public string GetHelperLibraryPath(RenderPipelineEnum renderPipeline, string shaderFolder) + { + string res; + switch (renderPipeline) + { + case RenderPipelineEnum.BIRP: + res = Constants.BIRP_HELPER_PATH; + break; + case RenderPipelineEnum.URP: + res = Constants.URP_HELPER_PATH; + break; + default: + res = string.Empty; + break; + } + + res = ConvertPathToRelative(res, shaderFolder); + + return res; + } + + private string GetPipelineFeatuersLibrary(RenderPipelineEnum renderPipeline, string shaderFolder) + { + string res = string.Empty; + + if (renderPipeline == RenderPipelineEnum.URP) + { + res = "Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl"; + } + + res = ConvertPathToRelative(res, shaderFolder); + + return res; + } + + private string GetPipelineFeaturesDefinesPath(RenderPipelineEnum renderPipeline, string shaderFolder) + { + string res = string.Empty; + + if (renderPipeline == RenderPipelineEnum.URP) + { + res = "Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl"; + } + + res = ConvertPathToRelative(res, shaderFolder); + + return res; + } + + private string GetPipelinePassSymbol(RenderPipelineEnum renderPipeline) + { + string res = string.Empty; + + switch (renderPipeline) + { + case RenderPipelineEnum.BIRP: + res = BIRP_PASS_SYMBOL; + break; + case RenderPipelineEnum.URP: + res = URP_PASS_SYMBOL; + break; + } + + return res; + } + + public string GetStencilBlockShaderEntry(EffectsProfile effectsProfile) + { + string res = string.Empty; + + + if (passType == AllIn13DPassType.OUTLINE) + { + res = STENCIL_BLOCK_OUTLINE; + } + else if(passType == AllIn13DPassType.MAIN) + { + res = STENCIL_BLOCK_MAIN_PASS; + } + + return res; + } + + public string GetPipelineFeaturesDefinesShaderEntry(RenderPipelineEnum renderPipeline, string shaderFolder) + { + string definesFilePath = GetPipelineFeaturesDefinesPath(renderPipeline, shaderFolder); + + string res = CreateIncludeShaderEntry(definesFilePath); + return res; + } + + public string GetPipelineFeaturesLibraryShaderEntry(RenderPipelineEnum renderPipeline, string shaderFolder) + { + string libraryPath = GetPipelineFeatuersLibrary(renderPipeline, shaderFolder); + string res = GetIncludeWithPragmaShaderEntry(libraryPath); + + return res; + } + + public string GetPipelinePassSymbolShaderEntry(RenderPipelineEnum renderPipeline) + { + string pipelineSymbol = GetPipelinePassSymbol(renderPipeline); + string res = string.Format(DEFINE_SHADER_ENTRY_FORMAT, pipelineSymbol); + + return res; + } + + public string GetIncludeWithPragmaShaderEntry(string path) + { + string res = string.Format(INCLUDE_WITH_PRAGMA_SHADER_ENTRY_FORMAT, path); + return res; + } + + public string CreateIncludeShaderEntry(string value) + { + string res = string.Format(INCLUDE_SHADER_ENTRY_FORMAT, value); + return res; + } + + public string GetPassSymbolShaderEntry() + { + string res = string.Format(DEFINE_SHADER_ENTRY_FORMAT, passSymbol); + return res; + } + + public string GetLightLibraryShaderEntry(string shaderFolder) + { + string res = ConvertPathToRelative("Shaders/ShaderLibrary/AllIn13DShaderLight.hlsl", shaderFolder); + res = CreateIncludeShaderEntry(res); + + return res; + } + + public string GetCoreLibraryShaderEntry(string shaderFolder) + { + string res = ConvertPathToRelative("Shaders/ShaderLibrary/AllIn13DShaderCore.hlsl", shaderFolder); + res = CreateIncludeShaderEntry(res); + + return res; + } + + public string GetCommonStructsShaderEntry(string shaderFolder) + { + string res = ConvertPathToRelative("Shaders/ShaderLibrary/AllIn13DShader_CommonStructs.hlsl", shaderFolder); + res = CreateIncludeShaderEntry(res); + + return res; + } + + public string GetCommonFunctionsShaderEntry(string shaderFolder) + { + string res = ConvertPathToRelative("Shaders/ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl", shaderFolder); + res = CreateIncludeShaderEntry(res); + + return res; + } + + public string GetShaderFeaturesLibraryShaderEntry(string shaderFolder) + { + string res = ConvertPathToRelative("Shaders/ShaderLibrary/AllIn13DShader_Features.hlsl", shaderFolder); + res = GetIncludeWithPragmaShaderEntry(res); + + return res; + } + + public string GetLightModeShaderEntry(RenderPipelineEnum renderPipeline) + { + string res = string.Empty; + string lightTag = string.Empty; + if(renderPipeline == RenderPipelineEnum.BIRP) + { + lightTag = lightModeTagBIRP; + } + else if(renderPipeline == RenderPipelineEnum.URP) + { + lightTag = lightModeTagURP; + } + + if (!string.IsNullOrEmpty(lightTag)) + { + res = string.Format(LIGHT_MODE_ENTRY_FORMAT, lightTag); + } + + return res; + } + + public static string GetAllIn1FeaturesEntries(List enabledEntries) + { + string res = string.Empty; + for (int i = 0; i < enabledEntries.Count; i++) + { + res = AppendEntryKeywords(res, enabledEntries[i]); + } + + return res; + } + + public static string AppendEntryKeywords(string input, EffectsProfileEntry effectProfileEntry) + { + string res = input; + + List keywordsEnabled = new List(); + effectProfileEntry.CollectKeywords(keywordsEnabled); + + for (int i = 0; i < keywordsEnabled.Count; i++) + { + res += CreateDefineEntry(keywordsEnabled[i]); + res += "\n"; + } + + return res; + } + + + private string ConvertPathToRelative(string localPath, string shaderFolder) + { + string res = Path.Combine(GlobalConfiguration.GetRootPluginFolderPath(), localPath); + res = Path.GetRelativePath(shaderFolder, res); + + res = res.Replace("\\", "/"); + + return res; + } + + public string GetPassFilePath(string shaderFolder) + { + string res = string.Empty; + + switch (passType) + { + case AllIn13DPassType.MAIN: + res = Constants.MAIN_PASS_PATH; + break; + case AllIn13DPassType.DEPTH_NORMALS: + res = Constants.DEPTH_NORMALS_PASS_PATH; + break; + case AllIn13DPassType.DEPTH_ONLY: + res = Constants.DEPTH_ONLY_PASS_PATH; + break; + case AllIn13DPassType.FORWARD_ADD: + res = Constants.LIGHT_ADD_PASS_PATH; + break; + case AllIn13DPassType.META: + res = Constants.META_PASS_PATH; + break; + case AllIn13DPassType.NONE: + res = "UNDEFINED"; + break; + case AllIn13DPassType.OUTLINE: + res = Constants.OUTLINE_PASS_PATH; + break; + case AllIn13DPassType.SHADOW_CASTER: + res = Constants.SHADOW_CASTER_PASS_PATH; + break; + } + + res = ConvertPathToRelative(res, shaderFolder); + + return res; + } + + public static string CreateDefineEntry(string symbol) + { + string res = string.Format(DEFINE_SHADER_ENTRY_FORMAT, symbol); + return res; + } + + public string GetPassName(RenderPipelineEnum renderPipeline) + { + string res = passNameBIRP; + if(renderPipeline == RenderPipelineEnum.URP) + { + res = passNameURP; + } + + return res; + } + + public string GetEffectsLibrariesShaderEntry(EffectsProfile effectsProfile, string shaderFolder) + { + string res = string.Empty; + + List enabledEffectGroups = effectsProfile.GetEnabledEffectsGroups(); + + for(int i = 0; i < enabledEffectGroups.Count; i++) + { + string libraryFileName = enabledEffectGroups[i].effectGroupConfig.libraryFileName; + + if (!string.IsNullOrEmpty(libraryFileName)) + { + string path = string.Format(EFFECT_LIBRARY_PATH_FORMAT, libraryFileName); + path = ConvertPathToRelative(path, shaderFolder); + + string entry = CreateIncludeShaderEntry(path); + + res += entry; + res += "\n"; + } + } + + return res; + } + + public string GetExtraPragmaLines(RenderPipelineEnum renderPipeline) + { + string res = string.Empty; + + if(renderPipeline == RenderPipelineEnum.BIRP) + { + res = extraPragmaLinesBIRP; + } + else if(renderPipeline == RenderPipelineEnum.URP) + { + res = extraPragmaLinesURP; + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassConfig.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassConfig.cs.meta new file mode 100644 index 0000000..c87fdd3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassConfig.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: f0d35b40778f5ef47a14fca4766c770a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ShaderPassConfig.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZTestCommand.cs b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZTestCommand.cs new file mode 100644 index 0000000..948e0a0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZTestCommand.cs @@ -0,0 +1,61 @@ +using UnityEngine.Rendering; + +namespace AllIn13DShader +{ + [System.Serializable] + public class ZTestCommand : ShaderCommand + { + private const string SHADER_ENTRY_FORMAT = @"ZTest {0}"; + private const string STR_DEFINED_IN_PROPERTIES = @"[_ZTestMode]"; + + public CompareFunction zTestMode; + + protected override string GetShaderEntryFormat() + { + return SHADER_ENTRY_FORMAT; + } + + protected override string GetShaderEntryValueDefinedInCode() + { + string res = string.Empty; + + switch (zTestMode) + { + case CompareFunction.Disabled: + res = "Disabled"; + break; + case CompareFunction.Never: + res = "Never"; + break; + case CompareFunction.Less: + res = "Less"; + break; + case CompareFunction.Equal: + res = "Equal"; + break; + case CompareFunction.LessEqual: + res = "LEqual"; + break; + case CompareFunction.Greater: + res = "Greater"; + break; + case CompareFunction.NotEqual: + res = "NotEqual"; + break; + case CompareFunction.GreaterEqual: + res = "GEqual"; + break; + case CompareFunction.Always: + res = "Always"; + break; + } + + return res; + } + + protected override string GetShaderEntryValueDefinedInProperties() + { + return STR_DEFINED_IN_PROPERTIES; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZTestCommand.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZTestCommand.cs.meta new file mode 100644 index 0000000..06302fe --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZTestCommand.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: c3315b3dcfcd94b47a7e672699f6fab8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZTestCommand.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZWriteCommand.cs b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZWriteCommand.cs new file mode 100644 index 0000000..c6e1bd7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZWriteCommand.cs @@ -0,0 +1,27 @@ +namespace AllIn13DShader +{ + [System.Serializable] + public class ZWriteCommand : ShaderCommand + { + private const string SHADER_ENTRY_FORMAT = @"ZWrite {0}"; + private const string STR_DEFINED_IN_PROPERTIES = @"[_ZWrite]"; + + public bool zWriteOn; + + protected override string GetShaderEntryFormat() + { + return SHADER_ENTRY_FORMAT; + } + + protected override string GetShaderEntryValueDefinedInCode() + { + string res = zWriteOn ? "On" : "Off"; + return res; + } + + protected override string GetShaderEntryValueDefinedInProperties() + { + return STR_DEFINED_IN_PROPERTIES; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZWriteCommand.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZWriteCommand.cs.meta new file mode 100644 index 0000000..2505ece --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZWriteCommand.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: f5a579664b289374ba56c3d9cbc06664 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/ShadersConfigurator/ZWriteCommand.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates.meta b/Assets/Plugins/AllIn13DShader/Editor/Templates.meta new file mode 100644 index 0000000..4c21464 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9229c95fa0f8276458632bcd259dcf09 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_NoShadowCaster_Template.allIn13DTemplate b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_NoShadowCaster_Template.allIn13DTemplate new file mode 100644 index 0000000..49e988a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_NoShadowCaster_Template.allIn13DTemplate @@ -0,0 +1,113 @@ +Shader "AllIn13DShader/AllIn13DShaderOutline_NoShadowCaster" +{ + Properties + { + + } + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "12.0" + } + + + + Pass + { + Name "AllIn13D_Outline_URP" + Tags {"LightMode"="OutlinePass"} + + Blend [_BlendSrc] [_BlendDst] + Cull Front + + Stencil + { + Ref [_StencilRef] + Comp NotEqual + } + + HLSLPROGRAM + #pragma vertex OutlinePass_Vertex + #pragma fragment OutlinePass_Fragment + + #define URP_PASS + #define ALLIN1_OUTLINE_PASS + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_OutlinePass.hlsl" + + ENDHLSL + } + + + + + + + } + + SubShader + { + + + Pass + { + Name "AllIn13D_Outline" + + Blend [_BlendSrc] [_BlendDst] + Cull Front + + Stencil + { + Ref [_StencilRef] + Comp [_OutlineMode] + } + + HLSLPROGRAM + #pragma target 3.0 + + #pragma multi_compile_instancing + #pragma multi_compile_fog + #pragma multi_compile _ DOTS_INSTANCING_ON + + #pragma vertex OutlinePass_Vertex + #pragma fragment OutlinePass_Fragment + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_OutlinePass.hlsl" + ENDHLSL + } + + + } + + +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_NoShadowCaster_Template.allIn13DTemplate.meta b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_NoShadowCaster_Template.allIn13DTemplate.meta new file mode 100644 index 0000000..40fd22c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_NoShadowCaster_Template.allIn13DTemplate.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 04bc221c351f85c439000f5c7e9b5cba +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_NoShadowCaster_Template.allIn13DTemplate + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_Template.allIn13DTemplate b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_Template.allIn13DTemplate new file mode 100644 index 0000000..13bd9dd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_Template.allIn13DTemplate @@ -0,0 +1,119 @@ +Shader "AllIn13DShader/AllIn13DShaderOutline" +{ + Properties + { + + } + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "12.0" + } + + + + Pass + { + Name "AllIn13D_Outline_URP" + Tags {"LightMode"="OutlinePass"} + + Blend [_BlendSrc] [_BlendDst] + Cull Front + + Stencil + { + Ref [_StencilRef] + Comp [_OutlineMode] + } + + HLSLPROGRAM + #pragma vertex OutlinePass_Vertex + #pragma fragment OutlinePass_Fragment + + #define URP_PASS + #define ALLIN1_OUTLINE_PASS + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_OutlinePass.hlsl" + + ENDHLSL + } + + + + + + + + + } + + SubShader + { + + + Pass + { + Name "AllIn13D_Outline" + + Blend [_BlendSrc] [_BlendDst] + Cull Front + + Stencil + { + Ref [_StencilRef] + Comp [_OutlineMode] + } + + HLSLPROGRAM + #pragma target 3.0 + + #pragma multi_compile_instancing + #pragma multi_compile_fog + #pragma multi_compile _ DOTS_INSTANCING_ON + + #pragma vertex OutlinePass_Vertex + #pragma fragment OutlinePass_Fragment + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_OutlinePass.hlsl" + ENDHLSL + } + + + + + + + } + + +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_Template.allIn13DTemplate.meta b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_Template.allIn13DTemplate.meta new file mode 100644 index 0000000..9f2faae --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_Template.allIn13DTemplate.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 886cb55daaf1bed4ca149a9fc2e22ec1 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShaderOutline_Template.allIn13DTemplate + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_NoShadowCaster_Template.allIn13DTemplate b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_NoShadowCaster_Template.allIn13DTemplate new file mode 100644 index 0000000..5ac28b0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_NoShadowCaster_Template.allIn13DTemplate @@ -0,0 +1,32 @@ +Shader "AllIn13DShader/AllIn13DShader_NoShadowCaster" +{ + Properties + { + + } + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "12.0" + } + + + + + + + + + } + + SubShader + { + + + + } + + +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_NoShadowCaster_Template.allIn13DTemplate.meta b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_NoShadowCaster_Template.allIn13DTemplate.meta new file mode 100644 index 0000000..df9e4ad --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_NoShadowCaster_Template.allIn13DTemplate.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: f37c419d15d89df4f85ce3768f47b693 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_NoShadowCaster_Template.allIn13DTemplate + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_ShaderProperties.allIn13DData b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_ShaderProperties.allIn13DData new file mode 100644 index 0000000..343bad8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_ShaderProperties.allIn13DData @@ -0,0 +1,365 @@ +/**/ +_RenderPreset("Render Preset", Float) = 1 +[AdvancedProperty]_AdvancedConfigurationEnabled("Show Advanced Configuration", Float) = 0 +[Enum(UnityEngine.Rendering.BlendMode)]_BlendSrc ("Blend mode Source", Float) = 1 +[Enum(UnityEngine.Rendering.BlendMode)]_BlendDst ("Blend mode Destination", Float) = 0 +[AdvancedProperty][Enum(UnityEngine.Rendering.CullMode)]_CullingMode("Culling Mode", Float) = 2 +[AdvancedProperty][Enum(Off, 0, On, 1)]_ZWrite("Depth Write", float) = 1.0 +[AdvancedProperty][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestMode("Z Test Mode", float) = 4 +[AdvancedProperty][Enum(UnityEngine.Rendering.ColorWriteMask)]_ColorMask("Color Write Mask", float) = 15 +[AdvancedProperty][Toggle(_FOG_ON)] _FogOn("Fog On", Float) = 0 +[AdvancedProperty][Toggle(_SPHERIZE_NORMALS_ON)]_SpherizeNormals("Spherize Normals", Float) = 0.0 +[AdvancedProperty][Toggle(_USE_CUSTOM_TIME)] _UseCustomTime("Use Custom Time", Float) = 0 + +[SingleProperty]_MainTex ("Main Texture", 2D) = "white" {} +[SingleProperty]_Color("Color", Color) = (1, 1, 1, 1) +[SingleProperty]_GeneralAlpha("General Alpha", Range(0, 1)) = 1.0 + +//Color Ramp +[Effect(EffectID# COLOR_RAMP, GroupID# ColorEffects, CustomDrawer# COLOR_RAMP_EFFECT_DRAWER)][Toggle(_COLOR_RAMP_ON)]_ColorRampOn("Color Ramp", Float) = 0 +[EffectProperty(ParentEffect# COLOR_RAMP, Keywords(_COLOR_RAMP_ON), AllowReset# False)][KeywordEnum(BeforeLighting, AfterLighting)]_ColorRampLightingStage("Stage", Float) = 0.0 +[EffectProperty(COLOR_RAMP)][AllIn13DShaderGradientDrawer]_ColorRampTex("Color Ramp Tex", 2D) = "white" {} +[EffectProperty(COLOR_RAMP)]_ColorRampLuminosity("Color Ramp Luminosity", Range(0, 1)) = 0 +[EffectProperty(COLOR_RAMP)]_ColorRampBlend("Color Ramp Blend", Range(0, 1)) = 1 +[EffectProperty(COLOR_RAMP)]_ColorRampTiling("Tiling", Range(0.01, 10)) = 1.0 +[EffectProperty(COLOR_RAMP)]_ColorRampScrollSpeed("Scroll Speed", Float) = 0.0 + +//Lighting +[Effect(EffectID# LIGHTMODEL, GroupID# Lighting, ExtraPasses# (FORWARD_ADD))][KeywordEnum(None, Classic, Toon, ToonRamp, HalfLambert, FakeGI, FastLighting)] _LightModel ("Light Model", Float) = 1 +[EffectProperty(LIGHTMODEL, TOON)]_ToonCutoff("Toon Cutoff", Range(0, 1)) = 0.5 +[EffectProperty(LIGHTMODEL, TOON)]_ToonSmoothness("Toon Smoothness", Range(0, 1)) = 0.5 +[EffectProperty(LIGHTMODEL, TOONRAMP)][AllIn13DShaderGradientDrawer]_ToonRamp("Toon Ramp", 2D) = "white" {} +[EffectProperty(LIGHTMODEL, HALFLAMBERT)]_HalfLambertWrap("Half Lambert", Range(0, 1)) = 1 +[EffectProperty(LIGHTMODEL, FAKEGI)]_HardnessFakeGI("Fake GI Hardness", Range(0, 1)) = 0.75 + +//Shading Model +[Effect(EffectID# SHADINGMODEL, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(Basic, PBR)] _ShadingModel("Shading Model", Float) = 0 +[EffectProperty(SHADINGMODEL, PBR)]_Metallic("Metallic", Range(0, 1)) = 0 +[EffectProperty(SHADINGMODEL, PBR)]_Smoothness("Smoothness", Range(0, 1)) = 0.5 +[EffectProperty(ParentEffect# SHADINGMODEL, Keywords(_SHADINGMODEL_PBR), AllowReset# True)][Toggle(_METALLIC_MAP_ON)]_MetallicMapOn("Use Metallic(R) / Smoothness(A) Map?", Float) = 0.0 +[EffectProperty(ParentEffect# SHADINGMODEL, KeywordsOp# AND, Keywords(_SHADINGMODEL_PBR, _METALLIC_MAP_ON), AllowReset# True)]_MetallicMap("Metallic Map", 2D) = "white" {} + +//Specular +[Effect(EffectID# SPECULARMODEL, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(None, Classic, Toon, Anisotropic, AnisotropicToon)]_SpecularModel ("Specular Model", Float) = 0 +[EffectProperty(SPECULARMODEL, CLASSIC, TOON, ANISOTROPIC, ANISOTROPICTOON)]_SpecularAtten("Specular Attenuation", Range(0, 1)) = 0.5 +[EffectProperty(ParentEffect# SPECULARMODEL, IncompatibleWithKws(_SHADINGMODEL_PBR), Keywords(_SPECULARMODEL_CLASSIC, _SPECULARMODEL_TOON), AllowReset# True)]_Shininess("Shininess", Range(0.01, 25)) = 16.0 +[EffectProperty(ParentEffect# SPECULARMODEL, IncompatibleWithKws(_SHADINGMODEL_PBR), Keywords(_SPECULARMODEL_ANISOTROPIC, _SPECULARMODEL_ANISOTROPICTOON), AllowReset# True)]_AnisoShininess("Aniso Shininess", Range(0, 1)) = 0.85 +[EffectProperty(SPECULARMODEL, TOON, ANISOTROPICTOON)]_SpecularToonCutoff("Specular Toon Cutoff", Range(0, 1)) = 0.35 +[EffectProperty(SPECULARMODEL, TOON, ANISOTROPICTOON)]_SpecularToonSmoothness("Specular Toon Smoothness", Range(0, 1)) = 0.0 +[EffectProperty(SPECULARMODEL, CLASSIC, TOON, ANISOTROPIC, ANISOTROPICTOON)]_SpecularMap("Specular Map", 2D) = "white" {} +[EffectProperty(SPECULARMODEL, ANISOTROPIC, ANISOTROPICTOON)]_Anisotropy("Anisotropy", Range(-1, 1)) = 0.45 + +//Reflections +[Effect(EffectID# REFLECTIONS, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(None, Classic, Toon)]_Reflections("Reflections", Float) = 0.0 +[EffectProperty(REFLECTIONS, TOON)]_ToonFactor("Toon Factor", Range(0, 1)) = 0 +[EffectProperty(REFLECTIONS, CLASSIC, TOON)]_ReflectionsAtten("Attenuation", Range(0, 1)) = 0.5 + +//Normal Map +[Effect(EffectID# NORMAL_MAP, GroupID# Lighting, DependentOn# LIGHTMODEL, CustomDrawer# NORMAL_MAP_EFFECT_DRAWER)][Toggle(_NORMAL_MAP_ON)]_NormalMapEnabled("Normal Map", Float) = 0 +[NoScaleOffset][EffectProperty(NORMAL_MAP)]_NormalMap("Normal Map", 2D) = "bump" {} +[EffectProperty(NORMAL_MAP)]_NormalStrength("Normal Strength", Range(0.0, 10.0)) = 1.0 + +//Flat Normals +[Effect(EffectID# FLAT_NORMALS, GroupID# Lighting, DependentOn# LIGHTMODEL)][Toggle(_FLAT_NORMALS_ON)]_FlatNormalsEnabled("Flat Normals", Float) = 0 +[EffectProperty(FLAT_NORMALS)]_FlatNormalsBlend("Blending", Range(0, 1)) = 1.0 + +//Custom Shadow Color +[Effect(EffectID# CUSTOM_SHADOW_COLOR, GroupID# Lighting)][Toggle(_CUSTOM_SHADOW_COLOR_ON)]_CustomShadowColorOn("Custom Shadow Color", Float) = 0 + +//Lightmaps +[Effect(EffectID# AFFECTED_BY_LIGHTMAPS, GroupID# Lighting)][Toggle(_AFFECTED_BY_LIGHTMAPS_ON)]_AffectedByLightmaps("Affected by lightmaps", Float) = 0 +[EffectProperty(AFFECTED_BY_LIGHTMAPS)][Toggle(_LIGHTMAP_COLOR_CORRECTION_ON)]_LightmapColorCorrection("Lightmap Color Correction?", Float) = 0 +[EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueShiftLM("Hue Shift", Range(0, 360)) = 0 +[EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueSaturationLM("Hue Saturation", Range(0, 4)) = 1 +[EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueBrightnessLM("Hue Brightness", Range(0, 2)) = 1 +[EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_ContrastLM("Contrast", Range(0, 20)) = 1.0 +[EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_BrightnessLM("Brightness", Range(-2, 2)) = 0.0 + +//Affected By Ambient +[Effect(EffectID# CUSTOM_AMBIENT_LIGHT, GroupID# Lighting)][Toggle(_CUSTOM_AMBIENT_LIGHT_ON)]_CustomAmbientLightOn("Custom Ambient Light", Float) = 0.0 +[EffectProperty(CUSTOM_AMBIENT_LIGHT)]_CustomAmbientColor("Custom Ambient Color", Color) = (0.65, 0.65, 0.65, 1.0) + +//Cast Shadows Enabled +[Effect(EffectID# CAST_SHADOWS_ON, GroupID# Lighting, ExtraPasses# (SHADOW_CASTER))][Toggle(_CAST_SHADOWS_ON)]_CastShadowsOn("Cast Shadows", Float) = 1.0 + +//Receive Shadows +[Effect(EffectID# RECEIVE_SHADOWS, GroupID# Lighting, ExtraPasses# (SHADOW_CASTER))][Toggle(_RECEIVE_SHADOWS_ON)]_ReceiveShadows("Receive Shadows", Float) = 1.0 +[EffectProperty(RECEIVE_SHADOWS)][KeywordEnum(Classic, Stylized)] _ReceivedShadowsType("Shadow Type", Float) = 0 +[EffectProperty(ParentEffect# RECEIVE_SHADOWS, Keywords(_RECEIVEDSHADOWSTYPE_STYLIZED), AllowReset# True)] _ShadowCutoff("Cutoff", Range(0.001, 0.5)) = 0.2 + +//Scroll Texture +[Effect(EffectID# SCROLL_TEXTURE, GroupID# UVEffects)][Toggle(_SCROLL_TEXTURE_ON)]_ScrollTextureOn("Scroll Texture", Float) = 0 +[EffectProperty(SCROLL_TEXTURE)]_ScrollTextureX("Scroll X", Float) = 1.0 +[EffectProperty(SCROLL_TEXTURE)]_ScrollTextureY("Scroll Y", Float) = 1.0 + +//Screen Space UVs +[Effect(EffectID# SCREEN_SPACE_UV, GroupID# UVEffects, IncompatibleWith# TRIPLANAR_MAPPING)][Toggle(_SCREEN_SPACE_UV_ON)]_ScreenSpaceUVOn("Screen Space UV", Float) = 0.0 +[EffectProperty(SCREEN_SPACE_UV)]_ScaleWithCameraDistance("Scale with camera distance", Range(0, 1)) = 0.0 + +//Pixelate +[Effect(EffectID# PIXELATE, GroupID# UVEffects)][Toggle(_PIXELATE_ON)]_Pixelate("Pixelate", Float) = 0 +[EffectProperty(PIXELATE)]_PixelateSize("Pixelate Size", Range(4, 512)) = 32 + +//Stochastic Texture Sampling +[Effect(EffectID# STOCHASTIC_SAMPLING, GroupID# UVEffects)][Toggle(_STOCHASTIC_SAMPLING_ON)]_StochasticSampling("Stochastic Sampling", Float) = 0 +[EffectProperty(STOCHASTIC_SAMPLING)]_StochasticScale("Grid Scale", Range(0, 10)) = 3.464 +[EffectProperty(STOCHASTIC_SAMPLING)]_StochasticSkew("Grid Skew", Range(0, 3)) = 0.57735027 + +//Wave UV +[Effect(EffectID# WAVE_UV, GroupID# UVEffects)][Toggle(_WAVE_UV_ON)]_WaveUVOn("Wave UV On", Float) = 0 +[EffectProperty(WAVE_UV)]_WaveAmount("Wave Amount", Range(0, 25)) = 7 +[EffectProperty(WAVE_UV)]_WaveSpeed("Wave Speed", Range(0, 25)) = 10 +[EffectProperty(WAVE_UV)]_WaveStrength("Wave Strength", Range(0, 25)) = 7.5 +[EffectProperty(WAVE_UV)]_WaveX("Wave X Axis", Range(0, 1)) = 0 +[EffectProperty(WAVE_UV)]_WaveY("Wave Y Axis", Range(0, 1)) = 0.5 + +//AO Map +[Effect(EffectID# AOMAP, GroupID# ColorEffects)][Toggle(_AOMAP_ON)]_AOMapEnabled("AO Map", Float) = 0 +[EffectProperty(AOMAP)][NoScaleOffset]_AOMap("AO Map", 2D) = "white" {} +[EffectProperty(AOMAP)]_AOMapStrength("AO Strength", Range(0, 1)) = 1.0 +[EffectProperty(AOMAP)]_AOContrast("AO Contrast", Range(0, 1)) = 1.0 +[EffectProperty(AOMAP)]_AOColor("AO Color", Color) = (0, 0, 0, 0) + +//Highlights +[Effect(EffectID# HIGHLIGHTS, GroupID# ColorEffects)][Toggle(_HIGHLIGHTS_ON)]_Highlights("Highlights", Float) = 0 +[EffectProperty(HIGHLIGHTS)][HDR]_HighlightsColor("Highlights Color", Color) = (2, 2, 2, 1) +[EffectProperty(HIGHLIGHTS)]_HighlightsStrength("Highlights Strength", Range(0, 1)) = 1 +[EffectProperty(HIGHLIGHTS)]_HighlightCutoff("Highlight Cutoff", Range(0, 1)) = 0.5 +[EffectProperty(HIGHLIGHTS)]_HighlightSmoothness("Highlight Smoothness", Range(0, 1)) = 0.5 +[EffectProperty(HIGHLIGHTS)][Vector3]_HighlightOffset("Highlight Offset", Vector) = (0, 0, 0, 0) + +//Rim +[Effect(EffectID# RIM_LIGHTING, GroupID# ColorEffects)][Toggle(_RIM_LIGHTING_ON)]_RimLighting("Rim or Fresnel", Float) = 0 +[EffectProperty(ParentEffect# RIM_LIGHTING, Keywords(_RIM_LIGHTING_ON), AllowReset# False)][KeywordEnum(BeforeLighting, BeforeLightingLast, AfterLighting)]_RimLightingStage("Stage", Float) = 0.0 +[EffectProperty(RIM_LIGHTING)][HDR]_RimColor("Rim Color", Color) = (1, 1, 1, 1) +[EffectProperty(RIM_LIGHTING)]_RimAttenuation("Rim Attenuation", Range(0, 1)) = 1.0 +[EffectProperty(RIM_LIGHTING)]_MinRim("Min Rim", Range(0, 1)) = 0 +[EffectProperty(RIM_LIGHTING)]_MaxRim("Max Rim", Range(0, 1)) = 1.0 +[EffectProperty(RIM_LIGHTING)][Vector3]_RimOffset("Rim Offset", Vector) = (0, 0, 0, 0) + +//Greyscale +[Effect(EffectID# GREYSCALE, GroupID# ColorEffects)][Toggle(_GREYSCALE_ON)]_Greyscale("Greyscale", Float) = 0 +[EffectProperty(GREYSCALE)][KeywordEnum(BeforeLighting, AfterLighting)] _GreyScaleStage("Stage", Float) = 0 +[EffectProperty(GREYSCALE)] _GreyscaleLuminosity("Luminosity", Range(-1, 1)) = 0 +[EffectProperty(GREYSCALE)] _GreyscaleTintColor("Greyscale Tint", Color) = (1.0, 1.0, 1.0, 1.0) +[EffectProperty(GREYSCALE)] _GreyscaleBlending("Blending", Range(0, 1)) = 1 + +//Posterize +[Effect(EffectID# POSTERIZE, GroupID# ColorEffects)][Toggle(_POSTERIZE_ON)]_Posterize("Posterize", Float) = 0 +[EffectProperty(POSTERIZE)] _PosterizeNumColors("Number of Colors", Range(0,200)) = 8 +[EffectProperty(POSTERIZE)] _PosterizeGamma("Posterize Gamma", Range(0.1,10)) = 0.75 + +//Hand Drawn +[Effect(EffectID# HAND_DRAWN, GroupID# UVEffects)][Toggle(_HAND_DRAWN_ON)]_HandDrawn("Hand Drawn", Float) = 0 +[EffectProperty(HAND_DRAWN)]_HandDrawnAmount("Hand Drawn Amount", Range(0, 50)) = 10 +[EffectProperty(HAND_DRAWN)]_HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 + +//Distortion +[Effect(EffectID# UV_DISTORTION, GroupID# UVEffects)][Toggle(_UV_DISTORTION_ON)]_UVDistortion("Distortion", Float) = 0 +[EffectProperty(UV_DISTORTION)]_DistortTex("Distortion Texture", 2D) = "white" {} +[EffectProperty(UV_DISTORTION)]_DistortAmount("Distortion Amount", Range(0,4)) = 0.3 +[EffectProperty(UV_DISTORTION)]_DistortTexXSpeed("Scroll speed X", Range(-10,10)) = 2 +[EffectProperty(UV_DISTORTION)]_DistortTexYSpeed("Scroll speed Y", Range(-10,10)) = 2 + +//Vertex Shake +[Effect(EffectID# VERTEX_SHAKE, GroupID# MeshEffects)][Toggle(_VERTEX_SHAKE_ON)] _VertexShakeOn("Vertex Shake", Float) = 0 +[EffectProperty(VERTEX_SHAKE)][Vector3] _ShakeSpeed("Speed", Vector) = (41, 49, 45, 0) +[EffectProperty(VERTEX_SHAKE)] _ShakeSpeedMult("Shake Mult", Float) = 1.0 +[EffectProperty(VERTEX_SHAKE)][Vector3] _ShakeMaxDisplacement("Shake Max Displacement", Vector) = (0.1, 0.1, 0.1, 0) +[EffectProperty(VERTEX_SHAKE)] _ShakeBlend("Shake Blend", Range(0, 1)) = 1.0 + +//Vertex Inflate +[Effect(EffectID# VERTEX_INFLATE, GroupID# MeshEffects)][Toggle(_VERTEX_INFLATE_ON)] _VertexInflate("Vertex Inflate", Float) = 0 +[EffectProperty(VERTEX_INFLATE)]_MinInflate("Min Inflate", Float) = 0.0 +[EffectProperty(VERTEX_INFLATE)]_MaxInflate("Max Inflate", Float) = 0.2 +[EffectProperty(VERTEX_INFLATE)]_InflateBlend("Inflate blend", Range(0, 1)) = 1.0 + +//Vertex Distortion +[Effect(EffectID# VERTEX_DISTORTION, GroupID# MeshEffects)][Toggle(_VERTEX_DISTORTION_ON)]_VertexDistortionOn("Vertex Distortion", Float) = 0 +[EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseTex("Noise Tex", 2D) = "white" {} +[EffectProperty(VERTEX_DISTORTION)]_VertexDistortionAmount("Distortion Amount", Range(0, 2)) = 0 +[EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseSpeedX("Scroll Speed X", Range(-10, 10)) = 4.0 +[EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseSpeedY("Scroll Speed Y", Range(-10, 10)) = 4.0 + + +//Voxelize +[Effect(EffectID# VOXELIZE, GroupID# MeshEffects)][Toggle(_VOXELIZE_ON)] _Voxelize("Voxelize", Float) = 0 +[EffectProperty(VOXELIZE)]_VoxelSize("Voxel Size", Range(0.1, 500)) = 100 +[EffectProperty(VOXELIZE)]_VoxelBlend("Blend Amount", Range(0, 1)) = 1 + +//Glitch +[Effect(EffectID# GLITCH, GroupID# MeshEffects)][Toggle(_GLITCH_ON)]_Glitch("Glitch", Float) = 0 +[EffectProperty(GLITCH)]_GlitchTiling ("Glitch Tiling", Float) = 5 +[EffectProperty(GLITCH)]_GlitchAmount ("Glitch Amount", Range(0, 1)) = 0.5 +[EffectProperty(GLITCH)]_GlitchOffset ("Glitch Offset", Vector) = (-0.5, 0, 0, 0) +[EffectProperty(GLITCH)]_GlitchSpeed ("Glitch Speed", Float) = 2.5 +[EffectProperty(GLITCH)][Toggle]_GlitchWorldSpace ("Use World Space", Float) = 1 + +//Recalculate Normals +[Effect(EffectID# RECALCULATE_NORMALS, GroupID# MeshEffects)][Toggle(_RECALCULATE_NORMALS_ON)]_RecalculateNormals("Recalculate Normals", Float) = 0 + +//Wind +[Effect(EffectID# WIND, GroupID# MeshEffects)][Toggle(_WIND_ON)]_WindOn("Wind", Float) = 0 +[EffectProperty(WIND)]_WindAttenuation("Attenuation", Range(0, 1)) = 1.0 +[EffectProperty(WIND)][Toggle(_USE_WIND_VERTICAL_MASK)]_UseVerticalMask("Use Vertical Mask?", Float) = 1.0 +[EffectProperty(ParentEffect# WIND, Keywords(_USE_WIND_VERTICAL_MASK), AllowReset# True)]_WindVerticalMaskMinY("Min Y", Float) = -1.0 +[EffectProperty(ParentEffect# WIND, Keywords(_USE_WIND_VERTICAL_MASK), AllowReset# True)]_WindVerticalMaskMaxY("Max Y", Float) = 1.0 + +//Hue Shift +[Effect(EffectID# HUE_SHIFT, GroupID# ColorEffects)][Toggle(_HUE_SHIFT_ON)] _HueShiftEnabled("Hue Shift", Float) = 0 +[EffectProperty(HUE_SHIFT)]_HueShift("Hue Shift", Range(0, 360)) = 0 +[EffectProperty(HUE_SHIFT)]_HueSaturation("Saturation", Range(0, 4)) = 1 +[EffectProperty(HUE_SHIFT)]_HueBrightness("Brightness", Range(0, 2)) = 1 + +//Emission +[Effect(EffectID# EMISSION, GroupID# ColorEffects)][Toggle(_EMISSION_ON)] _EmissionEnabled("Emission", Float) = 0 +[EffectProperty(EMISSION)]_EmissionSelfGlow("Emission Self Glow", Range(0, 20)) = 1 +[EffectProperty(EMISSION)][HDR]_EmissionColor("Emission Color", Color) = (1, 1, 1, 1) +[EffectProperty(EMISSION)]_EmissionMap("Emission Map", 2D) = "white" {} + +//Hologram +[Effect(EffectID# HOLOGRAM, GroupID# ColorEffects)][Toggle(_HOLOGRAM_ON)] _Hologram("Hologram", Float) = 0 +[EffectProperty(HOLOGRAM)][HDR]_HologramColor("Hologram Color", Color) = (1.25,2.8,6.8,1) +[EffectProperty(HOLOGRAM)]_HologramLineDirection("Line Direction", Vector) = (0,1,0,0) +[EffectProperty(HOLOGRAM)]_HologramBaseAlpha("Hologram Base Alpha", Range(0, 1)) = 0.1 + +[EffectProperty(HOLOGRAM)]_HologramScrollSpeed("Hologram Scroll Speed", Float) = 2 +[EffectProperty(HOLOGRAM)]_HologramFrequency("Hologram Frequency", Float) = 20 +[EffectProperty(HOLOGRAM)]_HologramAlpha("Hologram Alpha", Range(0, 1)) = 1 + +[EffectProperty(HOLOGRAM)]_HologramAccentSpeed("Hologram Accent Speed", Float) = 1 +[EffectProperty(HOLOGRAM)]_HologramAccentFrequency("Hologram Accent Frequency", Float) = 2 +[EffectProperty(HOLOGRAM)]_HologramAccentAlpha("Hologram Accent Alpha", Range(0, 1)) = 0.5 + +[EffectProperty(HOLOGRAM)]_HologramLineCenter("Hologram Line Center", Range(0, 1)) = 0.5 +[EffectProperty(HOLOGRAM)]_HologramLineSpacing("Hologram Line Spacing", Range(0.001, 5)) = 2.0 +[EffectProperty(HOLOGRAM)]_HologramLineSmoothness("Hologram Line Smoothness", Range(0.01, 5)) = 2.0 + +//Matcap +[Effect(EffectID# MATCAP, GroupID# ColorEffects)][Toggle(_MATCAP_ON)]_Matcap("Matcap", Float) = 0 +[EffectProperty(MATCAP)][KeywordEnum(Multiply, Replace)]_MatcapBlendMode("Blend Mode", Float) = 0 +[EffectProperty(MATCAP)][NoScaleOffset]_MatcapTex("Matcap Tex", 2D) = "white" {} +[EffectProperty(MATCAP)]_MatcapIntensity("Matcap Intensity", Range(0, 10)) = 1.0 +[EffectProperty(MATCAP)]_MatcapBlend("Matcap Blend", Range(0, 1)) = 1.0 + +//Hit +[Effect(EffectID# HIT, GroupID# ColorEffects)][Toggle(_HIT_ON)] _Hit("Hit", Float) = 0 +[EffectProperty(HIT)]_HitColor("Hit Color", Color) = (1, 1, 1, 1) +[EffectProperty(HIT)]_HitGlow("Hit Glow", Range(0, 100)) = 5 +[EffectProperty(HIT)]_HitBlend("Hit Blend", Range(0, 1)) = 1.0 + +//Contrast and Brightness +[Effect(EffectID# CONTRAST_BRIGHTNESS, GroupID# ColorEffects)][Toggle(_CONTRAST_BRIGHTNESS_ON)]_ContrastBrightnessOn("Contrast and Brightness", Float) = 0 +[EffectProperty(CONTRAST_BRIGHTNESS)]_Contrast("Contrast", Range(0, 10)) = 1.0 +[EffectProperty(CONTRAST_BRIGHTNESS)]_Brightness("Brightness", Range(-1, 1)) = 0.0 + +//Height Gradient +[Effect(EffectID# HEIGHT_GRADIENT, GroupID# ColorEffects)][Toggle(_HEIGHT_GRADIENT_ON)]_HeightGradientOn("Height Gradient", Float) = 0 +[EffectProperty(HEIGHT_GRADIENT)][KeywordEnum(Local, World)]_HeightGradientPositionSpace("Position Space", Float) = 0 +[EffectProperty(HEIGHT_GRADIENT)]_MinGradientHeight("Min Height", Float) = 0.0 +[EffectProperty(HEIGHT_GRADIENT)]_MaxGradientHeight("Max Height", Float) = 0.75 +[EffectProperty(HEIGHT_GRADIENT)][HDR]_GradientHeightColor01("Gradient Color 01", Color) = (0.2, 0.2, 0.2, 1) +[EffectProperty(HEIGHT_GRADIENT)][HDR]_GradientHeightColor02("Gradient Color 02", Color) = (1, 1, 1, 1) + +//Intersection Glow +[Effect(EffectID# INTERSECTION_GLOW, GroupID# ColorEffects)][Toggle(_INTERSECTION_GLOW_ON)]_IntersectionGlowOn("Intersection Glow", Float) = 0 +[EffectProperty(INTERSECTION_GLOW)]_DepthGlowDist("Depth Distance", Range(0.01, 10)) = 0.2 +[EffectProperty(INTERSECTION_GLOW)]_DepthGlowPower("Depth Power", Float) = 25.0 +[EffectProperty(INTERSECTION_GLOW)]_DepthGlowColor("Depth Glow Color", Color) = (1.0, 0.987, 0.6, 1.0) +[EffectProperty(INTERSECTION_GLOW)]_DepthGlowColorIntensity("Color Intensity", Float) = 25.0 +[EffectProperty(INTERSECTION_GLOW)]_DepthGlowGlobalIntensity("Global Intensity", Float) = 2.0 + +//Albedo from Vertex Color +[Effect(EffectID# ALBEDO_VERTEX_COLOR, GroupID# ColorEffects)][Toggle(_ALBEDO_VERTEX_COLOR_ON)]_AlbedoVertexColorOn("Albedo From Vertex Color", Float) = 0 +[EffectProperty(ALBEDO_VERTEX_COLOR)][KeywordEnum(Multiply, Replace)]_AlbedoVertexColorMode("Mode", Float) = 1 +[EffectProperty(ALBEDO_VERTEX_COLOR)]_VertexColorBlending("Blending", Range(0, 1)) = 1.0 + +//Triplanar Mapping +[Effect(EffectID# TRIPLANAR_MAPPING, GroupID# ColorEffects, IncompatibleWith# SCREEN_SPACE_UV, CustomDrawer# TRIPLANAR_EFFECT_DRAWER)][Toggle(_TRIPLANAR_MAPPING_ON)]_TriplanarMappingOn("Triplanar Mapping", Float) = 0 +[EffectProperty(TRIPLANAR_MAPPING)][KeywordEnum(Local, World)] _TriplanarNormalSpace("UV Space", Float) = 1.0 +[EffectProperty(TRIPLANAR_MAPPING)]_TriplanarTopTex("Top Texture", 2D) = "white" {} +[NoScaleOffset][EffectProperty(TRIPLANAR_MAPPING)]_TriplanarTopNormalMap("Top Normal Map", 2D) = "bump" {} +[EffectProperty(TRIPLANAR_MAPPING)]_TopNormalStrength("Top Normal Map Strength", Range(0.0, 10.0)) = 1.0 +[EffectProperty(TRIPLANAR_MAPPING)]_FaceDownCutoff("Face Down Cutoff", Range(-1, 1)) = 0.25 +[EffectProperty(TRIPLANAR_MAPPING)]_TriplanarSharpness("Sharpness", Range(1, 200)) = 15.0 +[EffectProperty(TRIPLANAR_MAPPING)][Toggle(_TRIPLANAR_NOISE_TRANSITION_ON)]_TriplanarNoiseTransitionOn("Noise Transition", Float) = 0 +[EffectProperty(ParentEffect# TRIPLANAR_MAPPING, Keywords(_TRIPLANAR_NOISE_TRANSITION_ON), AllowReset# True)] _TriplanarNoiseTex("Noise Tex", 2D) = "white" {} +[EffectProperty(ParentEffect# TRIPLANAR_MAPPING, Keywords(_TRIPLANAR_NOISE_TRANSITION_ON), AllowReset# True)] _TriplanarTransitionPower("Transition Power", Range(0, 1.0)) = 0.75 + +//Texture Blending +[Effect(EffectID# TEXTURE_BLENDING, GroupID# ColorEffects, CustomDrawer# TEXTURE_BLENDING_EFFECT_DRAWER)][Toggle(_TEXTURE_BLENDING_ON)]_TextureBlending ("Texture Blending", Float) = 0 +[EffectProperty(TEXTURE_BLENDING)][KeywordEnum(VertexColor, Texture)]_TextureBlendingSource("Source", Float) = 0 +[EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE), AllowReset# True)]_TexBlendingMask("Texture Blending Mask", 2D) = "white" {} +[EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffG("Cutoff (G)", Range(0, 1)) = 0.1 +[EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessG("Smoothness (G)", Range(0, 1)) = 0.4 +[EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffB("Cutoff (B)", Range(0, 1)) = 0.1 +[EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessB("Smoothness (B)", Range(0, 1)) = 0.4 +[EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffWhite("Cutoff (White)", Range(0, 1)) = 0.15 +[EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessWhite("Smoothness (White)", Range(0, 1)) = 0.4 +[EffectProperty(TEXTURE_BLENDING)][KeywordEnum(RGB, BlackAndWhite)]_TextureBlendingMode("Blending Mode", Float) = 0 +[EffectProperty(TEXTURE_BLENDING)]_BlendingTextureG("Blending Texture (G)", 2D) = "white" {} +[EffectProperty(TEXTURE_BLENDING)]_BlendingTextureB("Blending Texture (B)", 2D) = "white" {} +[EffectProperty(TEXTURE_BLENDING)]_BlendingTextureWhite("Blending Texture (White)", 2D) = "white" {} +[NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapG("Blending Normal Map (G)", 2D) = "bump" {} +[NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapB("Blending Normal Map (B)", 2D) = "bump" {} +[NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapWhite("Blending Normal Map (White)", 2D) = "bump" {} + +//Depth Coloring +[Effect(EffectID# DEPTH_COLORING, GroupID# ColorEffects)][Toggle(_DEPTH_COLORING_ON)]_DepthColoringOn("Depth Coloring", Float) = 0 + +//Sub surface scattering +[Effect(EffectID# SUBSURFACE_SCATTERING, GroupID# ColorEffects)][Toggle(_SUBSURFACE_SCATTERING_ON)]_SubsurfaceScattering("Fake Subsurface Scattering", Float) = 0.0 +[EffectProperty(SUBSURFACE_SCATTERING)]_NormalInfluence("Normal Influence", Range(0, 2.5)) = 0.5 +[EffectProperty(SUBSURFACE_SCATTERING)]_SSSPower("SSS Power", Range(0.01, 20)) = 1.0 +[EffectProperty(SUBSURFACE_SCATTERING)]_SSSFrontPower("SSS Front Power", Range(0.2, 20)) = 3.0 +[EffectProperty(SUBSURFACE_SCATTERING)]_SSSFrontAtten("SSS Front Atten", Range(0, 1)) = 0.3 +[EffectProperty(SUBSURFACE_SCATTERING)]_SSSAtten("SSS General Atten", Range(0, 1)) = 1.0 +[EffectProperty(SUBSURFACE_SCATTERING)][HDR]_SSSColor("SSS Color", Color) = (1.0, 1.0, 1.0, 1.0) +[EffectProperty(SUBSURFACE_SCATTERING)]_SSSMap("SSS Map", 2D) = "white" {} + +//Alpha Cutoff +[Effect(EffectID# ALPHA_CUTOFF, GroupID# AlphaEffects)][Toggle(_ALPHA_CUTOFF_ON)]_AlphaCutoffOn("Alpha Cutoff", Float) = 1.0 +[EffectProperty(ALPHA_CUTOFF)]_AlphaCutoffValue("Cutoff Value", Range(0, 1)) = 0.25 + +//Fade +[Effect(EffectID# FADE, GroupID# AlphaEffects)][Toggle(_FADE_ON)]_FadeOn("Fade", Float) = 0 +[EffectProperty(FADE)]_FadeTex("Fade Tex", 2D) = "white" {} +[EffectProperty(FADE)][KeywordEnum(UV1, UV2, WORLD_SPACE)]_FadeUVSet("UV Set", Float) = 0 +[EffectProperty(FADE)]_FadeAmount("Fade Amount", Range(0, 1)) = 0.0 +[EffectProperty(FADE)]_FadePower("Fade Power", Range(0.25, 4.0)) = 1.0 +[EffectProperty(FADE)]_FadeTransition("Fade Transition", Range(0, 0.4)) = 0.2 +[EffectProperty(FADE)][Toggle(_FADE_BURN_ON)]_FadeBurnOn("Use Fade Burn Color?", Float) = 0.0 +[EffectProperty(ParentEffect# FADE, Keywords(_FADE_BURN_ON), AllowReset# True)][HDR]_FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) +[EffectProperty(ParentEffect# FADE, Keywords(_FADE_BURN_ON), AllowReset# True)]_FadeBurnWidth("Fade Burn Width", Range(0, 0.2)) = 0.01 + +//Intersection Fade +[Effect(EffectID# INTERSECTION_FADE, GroupID# AlphaEffects)][Toggle(_INTERSECTION_FADE_ON)]_IntersectionFadeOn("Intersection Fade", Float) = 0.0 +[EffectProperty(INTERSECTION_FADE)]_IntersectionFadeFactor("Intersection Fade Factor", Range(0.1, 3.0)) = 1.0 + +//Alpha Round +[Effect(EffectID# ALPHA_ROUND, GroupID# AlphaEffects)][Toggle(_ALPHA_ROUND_ON)]_AlphaRoundOn("Alpha Round", Float) = 0 + +//Fade By Cam Distance +[Effect(EffectID# FADE_BY_CAM_DISTANCE, GroupID# AlphaEffects)][Toggle(_FADE_BY_CAM_DISTANCE_ON)]_FadeByCamDistanceOn("Fade By Cam Distance", Float) = 0 +[EffectProperty(FADE_BY_CAM_DISTANCE)][Toggle(_FADE_BY_CAM_DISTANCE_NEAR_FADE)]_NearFade("Near Fade", Float) = 0 +[EffectProperty(FADE_BY_CAM_DISTANCE)]_MinDistanceToFade("Min Distance", Float) = 0 +[EffectProperty(FADE_BY_CAM_DISTANCE)]_MaxDistanceToFade("Max Distance", Float) = 100 + +//Dither +[Effect(EffectID# DITHER, GroupID# AlphaEffects)][Toggle(_DITHER_ON)]_DitherOn("Dither", Float) = 0 +[EffectProperty(DITHER)]_DitherScale("Scale", Range(0.01, 2)) = 1 + +// +[Effect(EffectID# OUTLINETYPE, GroupID# OtherEffects, ExtraPasses# (OUTLINE))][KeywordEnum(None, Simple, Constant, FadeWithDistance)]_OutlineType("Outline Type", Float) = 0 + +// +[PerRendererData]_TimingSeed("Timing Seed", Float) = 0 + + +[EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)][HDR]_OutlineColor("Outline Color", Color) = (0, 0, 0, 1) +[EffectProperty(OUTLINETYPE, CONSTANT)]_MaxCameraDistance("Max Camera Distance", Float) = 1000 +[EffectProperty(OUTLINETYPE, FADEWITHDISTANCE)]_MaxFadeDistance("Max Fade Distance", Float) = 250 +[EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)]_OutlineThickness("Outline Thickness", Float) = 1 +[EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)][Enum(Basic, 8, Clean, 6)]_OutlineMode("Outline Mode", Float) = 8 +[IntRange]_StencilRef("Stencil Reference Value", Range(1, 255)) = 1 +/**/ \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_ShaderProperties.allIn13DData.meta b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_ShaderProperties.allIn13DData.meta new file mode 100644 index 0000000..7075722 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_ShaderProperties.allIn13DData.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: f305286a585cdaa41a9c9773cb033d92 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Templates/AllIn13DShader_ShaderProperties.allIn13DData + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/HLSLLibrary_Template.allIn13DTemplate b/Assets/Plugins/AllIn13DShader/Editor/Templates/HLSLLibrary_Template.allIn13DTemplate new file mode 100644 index 0000000..9431257 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/HLSLLibrary_Template.allIn13DTemplate @@ -0,0 +1,6 @@ +#ifndef +#define + + + +#endif // \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/HLSLLibrary_Template.allIn13DTemplate.meta b/Assets/Plugins/AllIn13DShader/Editor/Templates/HLSLLibrary_Template.allIn13DTemplate.meta new file mode 100644 index 0000000..065175a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/HLSLLibrary_Template.allIn13DTemplate.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 965f5e548a8980848a9769767878f300 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Templates/HLSLLibrary_Template.allIn13DTemplate + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/ShadersCreatorTool.cs b/Assets/Plugins/AllIn13DShader/Editor/Templates/ShadersCreatorTool.cs new file mode 100644 index 0000000..840392e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/ShadersCreatorTool.cs @@ -0,0 +1,107 @@ +using System.IO; +using System.Text.RegularExpressions; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public static class ShadersCreatorTool + { + private const string TEMPLATE_EXTENSION = ".allIn13DTemplate"; + + private const string STENCIL_BLOCK_TEMPLATE_NAME = "StencilBlock"; + + private static string[] TEMPLATES_NAMES = new string[] + { + "AllIn13DShaderOutline_NoShadowCaster_Template", + "AllIn13DShaderOutline_Template", + "AllIn13DShader_NoShadowCaster_Template", + }; + + private static string[] TEMPLATE_TAGS = new string[] + { + "COMMON_PROPERTIES", + "BASE_PASS", + "FORWARD_ADD_PASS", + "SHADOW_CASTER_PASS", + "CUSTOM_EDITOR", + "BASE_PASS_URP", + "SHADOW_CASTER_PASS_URP", + "DEPTH_ONLY_PASS_URP", + "DEPTH_NORMALS_PASS_URP", + "META_PASS_URP", + }; + + private const string REGEX_CORE = @"\/\*<{0}_START>\*\/\s*([\t\r\ ]*(?:.*\n)*)[\t\r\ ]*\s+\/\*<{0}_END>\*\/"; + private const string TAG_FORMAT = "<{0}>"; + + public static void BuildShaderFiles() + { + Shader mainShader = Shader.Find(Constants.SHADER_FULL_NAME_ALLIN13D); + string mainShaderPath = AssetDatabase.GetAssetPath(mainShader); + + string shaderFileText = File.ReadAllText(mainShaderPath); + + string stencilBlockPath = Path.Combine(Constants.TEMPLATES_FOLDER, STENCIL_BLOCK_TEMPLATE_NAME) + TEMPLATE_EXTENSION; + string stencilBlockContent = File.ReadAllText(stencilBlockPath); + + for (int i = 0; i < TEMPLATES_NAMES.Length; i++) + { + string templatePath = Path.Combine(Constants.TEMPLATES_FOLDER, TEMPLATES_NAMES[i]) + TEMPLATE_EXTENSION; + + string templateText = File.ReadAllText(templatePath); + string newShaderFileText = SearchAndReplaceTemplateTags(shaderFileText, templateText); + + if (TEMPLATES_NAMES[i] == "AllIn13DShaderOutline_NoShadowCaster_Template" || + TEMPLATES_NAMES[i] == "AllIn13DShaderOutline_Template") + { + newShaderFileText = newShaderFileText.Replace(@"/**/", stencilBlockContent); + } + + string newShaderFileName = TEMPLATES_NAMES[i].Replace("_Template", ""); + string newShaderPath = Path.Combine(Constants.SHADERS_GENERIC_FOLDER_PATH, newShaderFileName + ".shader"); + newShaderFileText = EditorUtils.UnifyEOL(newShaderFileText); + File.WriteAllText(newShaderPath, newShaderFileText); + } + + AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); + } + + private static string SearchAndReplaceTemplateTags(string shaderFileText, string templateText) + { + string res = templateText; + + for (int i = 0; i < TEMPLATE_TAGS.Length; i++) + { + string tagData = GetDataByTag(shaderFileText, TEMPLATE_TAGS[i]); + res = OverrideTagWithData(TEMPLATE_TAGS[i], tagData, res); + } + + return res; + } + + private static string GetDataByTag(string shaderFileTex, string tag) + { + string res = string.Empty; + + string regex = string.Format(REGEX_CORE, tag); + MatchCollection matchCollection = Regex.Matches(shaderFileTex, regex); + if(matchCollection.Count > 0) + { + res = matchCollection[0].Groups[1].Value.TrimStart().TrimEnd(); + } + + return res; + } + + private static string OverrideTagWithData(string tag, string data, string targetFileTxt) + { + string res = targetFileTxt; + + string formattedTag = string.Format(TAG_FORMAT, tag); + res = res.Replace(formattedTag, data); + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/ShadersCreatorTool.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Templates/ShadersCreatorTool.cs.meta new file mode 100644 index 0000000..8bca5f2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/ShadersCreatorTool.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: cbfc829814986aa428fd5296759d7687 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Templates/ShadersCreatorTool.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/StencilBlock.allIn13DTemplate b/Assets/Plugins/AllIn13DShader/Editor/Templates/StencilBlock.allIn13DTemplate new file mode 100644 index 0000000..eb29b32 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/StencilBlock.allIn13DTemplate @@ -0,0 +1,6 @@ +Stencil +{ + Ref [_StencilRef] + Comp Always + Pass Replace +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Templates/StencilBlock.allIn13DTemplate.meta b/Assets/Plugins/AllIn13DShader/Editor/Templates/StencilBlock.allIn13DTemplate.meta new file mode 100644 index 0000000..8a772d5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Templates/StencilBlock.allIn13DTemplate.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: d0d7c8b8879f3dc41ba9f7dff4a03e37 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Templates/StencilBlock.allIn13DTemplate + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Texture.meta b/Assets/Plugins/AllIn13DShader/Editor/Texture.meta new file mode 100644 index 0000000..9b330da --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Texture.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e832d27d49e595b4fa6ab08530f20f08 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Texture/AllIn13dShaderCustomEditorHeader.png b/Assets/Plugins/AllIn13DShader/Editor/Texture/AllIn13dShaderCustomEditorHeader.png new file mode 100644 index 0000000..1598ff0 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Editor/Texture/AllIn13dShaderCustomEditorHeader.png differ diff --git a/Assets/Plugins/AllIn13DShader/Editor/Texture/AllIn13dShaderCustomEditorHeader.png.meta b/Assets/Plugins/AllIn13DShader/Editor/Texture/AllIn13dShaderCustomEditorHeader.png.meta new file mode 100644 index 0000000..65b0aec --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Texture/AllIn13dShaderCustomEditorHeader.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: a809dbea5a55b18408389954731bd51c +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5e97eb03825dee720800000000000000 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Texture/AllIn13dShaderCustomEditorHeader.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/TextureSizes.cs b/Assets/Plugins/AllIn13DShader/Editor/TextureSizes.cs new file mode 100644 index 0000000..e52954a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/TextureSizes.cs @@ -0,0 +1,17 @@ +namespace AllIn13DShader +{ + public enum TextureSizes + { + _2 = 2, + _4 = 4, + _8 = 8, + _16 = 16, + _32 = 32, + _64 = 64, + _128 = 128, + _256 = 256, + _512 = 512, + _1024 = 1024, + _2048 = 2048 + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/TextureSizes.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/TextureSizes.cs.meta new file mode 100644 index 0000000..fb72506 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/TextureSizes.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 3bfc75873bcad9e40840bfc361b8d9ce +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/TextureSizes.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools.meta new file mode 100644 index 0000000..c9c1cd2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1d97a0c301d814b449fafcf9cd34c220 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerTool.cs b/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerTool.cs new file mode 100644 index 0000000..78c7bcc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerTool.cs @@ -0,0 +1,92 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class AtlasPackerTool + { + public AtlasPackerValues values; + + //public int atlasXCount; + //public int atlasYCount; + + //public TextureSizes atlasSizesX; + //public TextureSizes atlasSizesY; + + //public FilterMode atlasFiltering; + + //public bool squareAtlas; + + //public Texture2D[] atlas; + + //public Texture2D createdAtlas; + + public AtlasPackerTool() + { + ResetValues(); + + values.atlasXCount = 1; + values.atlasYCount = 1; + + values.atlasSizesX = TextureSizes._1024; + values.atlasSizesY = TextureSizes._1024; + + values.squareAtlas = true; + + values.atlasFiltering = FilterMode.Bilinear; + } + + public void ResetValues() + { + values = ScriptableObject.CreateInstance(); + values.atlas = new Texture2D[0]; + } + + public void CreateAtlas() + { + int atlasElements = values.atlasXCount * values.atlasYCount; + int atlasWidth = (int)values.atlasSizesX; + int atlasHeight = (int)values.atlasSizesY; + + Texture2D[] AtlasCopy = (Texture2D[])values.atlas.Clone(); + int textureXTargetWidth = atlasWidth / values.atlasXCount; + int textureYTargetHeight = atlasHeight / values.atlasYCount; + values.createdAtlas = new Texture2D(atlasWidth, atlasHeight); + for (int i = 0; i < values.atlasYCount; i++) + { + for (int j = 0; j < values.atlasXCount; j++) + { + int currIndex = (i * values.atlasXCount) + j; + bool hasImageForThisIndex = currIndex < AtlasCopy.Length && AtlasCopy[currIndex] != null; + if (hasImageForThisIndex) + { + EditorUtils.SetTextureReadWrite(AssetDatabase.GetAssetPath(AtlasCopy[currIndex]), true); + Texture2D copyTexture = new Texture2D(AtlasCopy[currIndex].width, AtlasCopy[currIndex].height); + copyTexture.SetPixels(AtlasCopy[currIndex].GetPixels()); + copyTexture.Apply(); + AtlasCopy[currIndex] = copyTexture; + AtlasCopy[currIndex] = EditorUtils.ScaleTexture(AtlasCopy[currIndex], textureXTargetWidth, textureYTargetHeight); + AtlasCopy[currIndex].Apply(); + } + + for (int y = 0; y < textureYTargetHeight; y++) + { + for (int x = 0; x < textureXTargetWidth; x++) + { + if (hasImageForThisIndex) values.createdAtlas.SetPixel((j * textureXTargetWidth) + x, (i * textureYTargetHeight) + y, AtlasCopy[currIndex].GetPixel(x, y)); + else values.createdAtlas.SetPixel((j * textureXTargetWidth) + x, (i * textureYTargetHeight) + y, new Color(0, 0, 0, 1)); + } + } + } + } + + values.createdAtlas.Apply(); + } + + public int GetAtlasElements() + { + int res = values.atlasXCount * values.atlasYCount; + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerTool.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerTool.cs.meta new file mode 100644 index 0000000..0a0d739 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerTool.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 22cf4eeb2432eff42a008c7a5c157f0f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerTool.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerValues.cs b/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerValues.cs new file mode 100644 index 0000000..db3ade7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerValues.cs @@ -0,0 +1,21 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class AtlasPackerValues : ScriptableObject + { + public int atlasXCount; + public int atlasYCount; + + public TextureSizes atlasSizesX; + public TextureSizes atlasSizesY; + + public FilterMode atlasFiltering; + + public bool squareAtlas; + + public Texture2D[] atlas; + + public Texture2D createdAtlas; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerValues.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerValues.cs.meta new file mode 100644 index 0000000..2157836 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerValues.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: c4c373390afce2e47a4129d7a5b822d2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/AtlasPackerValues.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/GradientCreatorTool.cs b/Assets/Plugins/AllIn13DShader/Editor/Tools/GradientCreatorTool.cs new file mode 100644 index 0000000..432592a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/GradientCreatorTool.cs @@ -0,0 +1,150 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class GradientCreatorTool + { + public const int HEIGHT_GRADIENT = 16; + + public Texture2D gradientTex; + + public TextureSizes gradientSizes; + public FilterMode gradientFiltering; + public Gradient gradient; + + public GradientCreatorTool() + { + gradientSizes = TextureSizes._128; + gradientFiltering = FilterMode.Bilinear; + gradient = new Gradient(); + + int size = (int)gradientSizes; + gradientTex = new Texture2D(size, size); + } + + public Texture2D CreateGradientTexture(TextureSizes gradientSizes, FilterMode gradientFiltering, Gradient gradient) + { + this.gradientSizes = gradientSizes; + this.gradientFiltering = gradientFiltering; + this.gradient = gradient; + + return CreateGradientTexture(); + } + + public Texture2D CreateGradientTexture(Gradient gradient) + { + this.gradientSizes = TextureSizes._256; + this.gradientFiltering = FilterMode.Bilinear; + this.gradient = gradient; + + return CreateGradientTexture(); + } + + public Texture2D CreateGradientTexture() + { + int textureSize = (int)gradientSizes; + this.gradientTex = new Texture2D(textureSize, HEIGHT_GRADIENT, TextureFormat.RGBA32, false); + this.gradientTex.wrapMode = TextureWrapMode.Clamp; + + for (int i = 0; i < textureSize; i++) + { + Color col = gradient.Evaluate((float)i / (float)textureSize); + for (int j = 0; j < HEIGHT_GRADIENT; j++) + { + gradientTex.SetPixel(i, j, gradient.Evaluate((float)i / (float)textureSize)); + } + } + + gradientTex.Apply(); + return gradientTex; + } + + public Texture SaveGradientTexture(GradientTexture gradientTextureAsset, bool createNewSO) + { + string texName = "RampTexture"; + if(gradientTextureAsset != null) + { + texName = gradientTextureAsset.texture.name; + } + + string directoryPath = GlobalConfiguration.instance.GradientSavePath; + if (gradientTextureAsset != null && AssetDatabase.IsMainAsset(gradientTextureAsset.texture) && !createNewSO) + { + string assetPath = AssetDatabase.GetAssetPath(gradientTextureAsset.texture); + directoryPath = Path.GetDirectoryName(assetPath); + } + Texture tex = EditorUtils.SaveTextureAsPNG(directoryPath, texName, "Ramp Texture", gradientTex, + FilterMode.Bilinear, TextureImporterType.Default, TextureWrapMode.Clamp, false, createNewSO); + + if (createNewSO) + { + GradientTexture gradientTexture = ScriptableObject.CreateInstance(); + gradientTexture.texture = tex; + gradientTexture.gradient = new Gradient(); + CopyGradient(gradient, gradientTexture.gradient); + + string gradientTextureAssetPath = Path.Combine(GlobalConfiguration.instance.GradientSavePath, $"GradientAsset_{tex.name}.asset"); + gradientTextureAssetPath = AssetDatabase.GenerateUniqueAssetPath(gradientTextureAssetPath); + + AssetDatabase.CreateAsset(gradientTexture, gradientTextureAssetPath); + AssetDatabase.Refresh(); + } + else + { + gradientTextureAsset.texture = tex; + + gradientTextureAsset.gradient = new Gradient(); + CopyGradient(gradient, gradientTextureAsset.gradient); + + EditorUtility.SetDirty(gradientTextureAsset); + } + + return tex; + } + + public static void CopyGradient(Gradient from, Gradient to) + { + GradientColorKey[] newColorKeys = new GradientColorKey[from.colorKeys.Length]; + GradientAlphaKey[] newAlphaKeys = new GradientAlphaKey[from.alphaKeys.Length]; + + for (int i = 0; i < from.colorKeys.Length; i++) + { + newColorKeys[i] = from.colorKeys[i]; + } + + for (int i = 0; i < from.alphaKeys.Length; i++) + { + newAlphaKeys[i] = from.alphaKeys[i]; + } + + to.colorKeys = newColorKeys; + to.alphaKeys = newAlphaKeys; + to.mode = from.mode; + } + + public static GradientTexture FindGradientTexureByTex(Texture selectedTex) + { + GradientTexture res = null; + string[] guids = AssetDatabase.FindAssets("t:GradientTexture"); + + for (int i = 0; i < guids.Length; i++) + { + string path = AssetDatabase.GUIDToAssetPath(guids[i]); + GradientTexture gradientTexture = AssetDatabase.LoadAssetAtPath(path); + + if (gradientTexture.name.StartsWith("GradientAsset_")) + { + if (gradientTexture.texture == selectedTex) + { + res = gradientTexture; + break; + } + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/GradientCreatorTool.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/GradientCreatorTool.cs.meta new file mode 100644 index 0000000..ddd8d50 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/GradientCreatorTool.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: d9a976b4a21c9a34884e574c601d7e55 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/GradientCreatorTool.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/NoiseCreatorTool.cs b/Assets/Plugins/AllIn13DShader/Editor/Tools/NoiseCreatorTool.cs new file mode 100644 index 0000000..2cd3316 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/NoiseCreatorTool.cs @@ -0,0 +1,126 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class NoiseCreatorTool + { + private const string SHADER_NAME_FRACTAL_NOISE = "AllIn13DShaderFractalNoise"; + private const string SHADER_NAME_WORLEY_NOISE = "AllIn13DShaderWorleyNoise"; + + public enum NoiseTypes + { + Fractal, + Perlin, + Billow, + Voronoi, + Water, + Cellular, + Cells1, + Cells2 + } + + public NoiseCreatorValues values; + + public NoiseCreatorTool() + { + values = new NoiseCreatorValues(); + + NoiseSetMaterial(); + CheckCreationNoiseTextures(); + UpdateNoiseMatAndRender(); + CreateNoiseTex(); + } + + public void CreateNoiseTex() + { + int texSize = (int)values.noiseSize; + values.finalNoiseTex = new Texture2D(texSize, texSize); + RenderTexture finalRenderTarget = new RenderTexture(values.finalNoiseTex.width, values.finalNoiseTex.height, 0, RenderTextureFormat.ARGB32); + Graphics.Blit(values.finalNoiseTex, finalRenderTarget, values.noiseMaterial); + values.finalNoiseTex.ReadPixels(new Rect(0, 0, finalRenderTarget.width, finalRenderTarget.height), 0, 0); + values.finalNoiseTex.Apply(); + } + + public void CheckCreationNoiseTextures() + { + if (values.noisePreview == null) + { + values.noisePreview = new Texture2D(256, 256); + } + + if (values.noiseRenderTarget == null) + { + values.noiseRenderTarget = new RenderTexture(values.noisePreview.width, values.noisePreview.height, 0, RenderTextureFormat.ARGB32); + } + } + + public void UpdateNoiseMatAndRender() + { + if (values.noiseType == NoiseTypes.Fractal || values.noiseType == NoiseTypes.Perlin || values.noiseType == NoiseTypes.Billow) + { + values.noiseMaterial.SetFloat("_EndBand", values.noiseFractalAmount); + } + else values.noiseMaterial.SetFloat("_Jitter", values.noiseJitter); + + values.noiseMaterial.SetFloat("_ScaleX", values.noiseScaleX); + values.noiseMaterial.SetFloat("_ScaleY", values.noiseScaleY); + values.noiseMaterial.SetFloat("_Offset", (float)values.noiseSeed); + values.noiseMaterial.SetFloat("_Contrast", values.noiseContrast); + values.noiseMaterial.SetFloat("_Brightness", values.noiseBrightness); + values.noiseMaterial.SetFloat("_Invert", values.noiseInverted ? 1f : 0f); + + Graphics.Blit(values.noisePreview, values.noiseRenderTarget, values.noiseMaterial); + values.noisePreview.ReadPixels(new Rect(0, 0, values.noiseRenderTarget.width, values.noiseRenderTarget.height), 0, 0); + values.noisePreview.Apply(); + } + + public void NoiseSetMaterial() + { + if (values.noiseType == NoiseTypes.Fractal || values.noiseType == NoiseTypes.Perlin || values.noiseType == NoiseTypes.Billow) + { + values.isFractalNoise = true; + values.noiseMaterial = new Material(EditorUtils.FindShader(SHADER_NAME_FRACTAL_NOISE)); + values.noiseScaleX = 4f; + values.noiseScaleY = 4f; + } + else + { + values.isFractalNoise = false; + values.noiseMaterial = new Material(EditorUtils.FindShader(SHADER_NAME_WORLEY_NOISE)); + values.noiseScaleX = 10f; + values.noiseScaleY = 10f; + } + + switch (values.noiseType) + { + case NoiseTypes.Fractal: + values.noiseFractalAmount = 8f; + values.noiseMaterial.SetFloat("_Fractal", 1); + break; + case NoiseTypes.Perlin: + values.noiseFractalAmount = 1f; + values.noiseMaterial.SetFloat("_Fractal", 1); + break; + case NoiseTypes.Billow: + values.noiseFractalAmount = 4f; + values.noiseMaterial.SetFloat("_Fractal", 0); + break; + case NoiseTypes.Voronoi: + values.noiseMaterial.SetFloat("_NoiseType", 0f); + break; + case NoiseTypes.Water: + values.noiseMaterial.SetFloat("_NoiseType", 3f); + break; + case NoiseTypes.Cellular: + values.noiseMaterial.SetFloat("_NoiseType", 4f); + break; + case NoiseTypes.Cells1: + values.noiseMaterial.SetFloat("_NoiseType", 1f); + break; + case NoiseTypes.Cells2: + values.noiseMaterial.SetFloat("_NoiseType", 2f); + break; + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/NoiseCreatorTool.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/NoiseCreatorTool.cs.meta new file mode 100644 index 0000000..36085e7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/NoiseCreatorTool.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: e268a0b97ec21eb4181d17530e323c9b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/NoiseCreatorTool.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/NormalMapCreatorTool.cs b/Assets/Plugins/AllIn13DShader/Editor/Tools/NormalMapCreatorTool.cs new file mode 100644 index 0000000..b9b8ba9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/NormalMapCreatorTool.cs @@ -0,0 +1,107 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class NormalMapCreatorTool + { + public Texture2D targetNormalImage; + public int normalSmoothing; + public float normalStrength; + public int isComputingNormals; + + public Texture2D CreateNormalMap(bool invertDirection) + { + int width = targetNormalImage.width; + int height = targetNormalImage.height; + Color[] sourcePixels = targetNormalImage.GetPixels(); + Color[] resultPixels = new Color[width * height]; + Vector3 vScale = new Vector3(0.3333f, 0.3333f, 0.3333f); + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + int index = x + y * width; + Vector3 cSampleNegXNegY = GetPixelClamped(sourcePixels, x - 1, y - 1, width, height); + Vector3 cSampleZerXNegY = GetPixelClamped(sourcePixels, x, y - 1, width, height); + Vector3 cSamplePosXNegY = GetPixelClamped(sourcePixels, x + 1, y - 1, width, height); + Vector3 cSampleNegXZerY = GetPixelClamped(sourcePixels, x - 1, y, width, height); + Vector3 cSamplePosXZerY = GetPixelClamped(sourcePixels, x + 1, y, width, height); + Vector3 cSampleNegXPosY = GetPixelClamped(sourcePixels, x - 1, y + 1, width, height); + Vector3 cSampleZerXPosY = GetPixelClamped(sourcePixels, x, y + 1, width, height); + Vector3 cSamplePosXPosY = GetPixelClamped(sourcePixels, x + 1, y + 1, width, height); + + float fSampleNegXNegY = Vector3.Dot(cSampleNegXNegY, vScale); + float fSampleZerXNegY = Vector3.Dot(cSampleZerXNegY, vScale); + float fSamplePosXNegY = Vector3.Dot(cSamplePosXNegY, vScale); + float fSampleNegXZerY = Vector3.Dot(cSampleNegXZerY, vScale); + float fSamplePosXZerY = Vector3.Dot(cSamplePosXZerY, vScale); + float fSampleNegXPosY = Vector3.Dot(cSampleNegXPosY, vScale); + float fSampleZerXPosY = Vector3.Dot(cSampleZerXPosY, vScale); + float fSamplePosXPosY = Vector3.Dot(cSamplePosXPosY, vScale); + + float edgeX = (fSampleNegXNegY - fSamplePosXNegY) * 0.25f + (fSampleNegXZerY - fSamplePosXZerY) * 0.5f + (fSampleNegXPosY - fSamplePosXPosY) * 0.25f; + float edgeY = (fSampleNegXNegY - fSampleNegXPosY) * 0.25f + (fSampleZerXNegY - fSampleZerXPosY) * 0.5f + (fSamplePosXNegY - fSamplePosXPosY) * 0.25f; + + if(invertDirection) edgeY = -edgeY; + + Vector2 vEdge = new Vector2(edgeX, edgeY) * normalStrength; + Vector3 norm = new Vector3(vEdge.x, vEdge.y, 1.0f).normalized; + resultPixels[index] = new Color(norm.x * 0.5f + 0.5f, norm.y * 0.5f + 0.5f, norm.z * 0.5f + 0.5f, 1); + } + } + + if (normalSmoothing > 0) + { + resultPixels = SmoothNormals(resultPixels, width, height, normalSmoothing); + } + + Texture2D texNormal = new Texture2D(width, height, TextureFormat.RGB24, false, false); + texNormal.SetPixels(resultPixels); + texNormal.Apply(); + return texNormal; + } + + private Vector3 GetPixelClamped(Color[] pixels, int x, int y, int width, int height) + { + x = Mathf.Clamp(x, 0, width - 1); + y = Mathf.Clamp(y, 0, height - 1); + Color c = pixels[x + y * width]; + return new Vector3(c.r, c.g, c.b); + } + + private Color[] SmoothNormals(Color[] pixels, int width, int height, int normalSmooth) + { + Color[] smoothedPixels = new Color[pixels.Length]; + float step = 0.00390625f * normalSmooth; + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + float pixelsToAverage = 0.0f; + Color c = pixels[x + y * width]; + pixelsToAverage++; + + for (int offsetY = -normalSmooth; offsetY <= normalSmooth; offsetY++) + { + for (int offsetX = -normalSmooth; offsetX <= normalSmooth; offsetX++) + { + if (offsetX == 0 && offsetY == 0) continue; + + int sampleX = Mathf.Clamp(x + offsetX, 0, width - 1); + int sampleY = Mathf.Clamp(y + offsetY, 0, height - 1); + + c += pixels[sampleX + sampleY * width]; + pixelsToAverage++; + } + } + + smoothedPixels[x + y * width] = c / pixelsToAverage; + } + } + + return smoothedPixels; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/NormalMapCreatorTool.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/NormalMapCreatorTool.cs.meta new file mode 100644 index 0000000..2f2cccf --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/NormalMapCreatorTool.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 377ab8b8193dc364ba6f648292b747d9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/NormalMapCreatorTool.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerTool.cs b/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerTool.cs new file mode 100644 index 0000000..bcf20d9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerTool.cs @@ -0,0 +1,83 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class RGBAPackerTool + { + public RGBAPackerValues values; + + public RGBAPackerTool() + { + values = ScriptableObject.CreateInstance(); + } + + public void CreateRGBATexture() + { + int textureSize = (int)values.textureSizes; + Texture2D rgbaTexture = new Texture2D(textureSize, textureSize, TextureFormat.RGBA32, false); + + // Get readable copies of input textures + Texture2D readableR = GetReadableTexture(values.rChannelTexture, textureSize); + Texture2D readableG = GetReadableTexture(values.gChannelTexture, textureSize); + Texture2D readableB = GetReadableTexture(values.bChannelTexture, textureSize); + Texture2D readableA = GetReadableTexture(values.aChannelTexture, textureSize); + + // Pack channels + for(int x = 0; x < textureSize; x++) + { + for(int y = 0; y < textureSize; y++) + { + float r = readableR != null ? readableR.GetPixel(x, y).r : (values.rChannelDefaultWhite ? 1f : 0f); + float g = readableG != null ? readableG.GetPixel(x, y).r : (values.gChannelDefaultWhite ? 1f : 0f); + float b = readableB != null ? readableB.GetPixel(x, y).r : (values.bChannelDefaultWhite ? 1f : 0f); + float a = readableA != null ? readableA.GetPixel(x, y).r : (values.aChannelDefaultWhite ? 1f : 0f); + + rgbaTexture.SetPixel(x, y, new Color(r, g, b, a)); + } + } + + rgbaTexture.Apply(); + values.createdRGBATexture = rgbaTexture; + + // Clean up temporary textures + if(readableR != values.rChannelTexture && readableR != null) Object.DestroyImmediate(readableR); + if(readableG != values.gChannelTexture && readableG != null) Object.DestroyImmediate(readableG); + if(readableB != values.bChannelTexture && readableB != null) Object.DestroyImmediate(readableB); + if(readableA != values.aChannelTexture && readableA != null) Object.DestroyImmediate(readableA); + } + + private Texture2D GetReadableTexture(Texture2D source, int targetSize) + { + if(source == null) return null; + + // Check if texture is already readable + try + { + source.GetPixel(0, 0); + // If we get here, texture is readable, but we might need to resize + if(source.width == targetSize && source.height == targetSize) + return source; + } + catch + { + // Texture is not readable, need to make a copy + } + + // Create readable copy + RenderTexture renderTexture = RenderTexture.GetTemporary(targetSize, targetSize, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); + Graphics.Blit(source, renderTexture); + + RenderTexture previous = RenderTexture.active; + RenderTexture.active = renderTexture; + + Texture2D readableTexture = new Texture2D(targetSize, targetSize, TextureFormat.RGBA32, false); + readableTexture.ReadPixels(new Rect(0, 0, targetSize, targetSize), 0, 0); + readableTexture.Apply(); + + RenderTexture.active = previous; + RenderTexture.ReleaseTemporary(renderTexture); + + return readableTexture; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerTool.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerTool.cs.meta new file mode 100644 index 0000000..f2f6af3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerTool.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 61842b6b60900c643ae3c6e441a44852 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerTool.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerValues.cs b/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerValues.cs new file mode 100644 index 0000000..c159d49 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerValues.cs @@ -0,0 +1,22 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [CreateAssetMenu(fileName = "RGBAPackerValues", menuName = "AllIn1 3D Shader/RGBA Packer Values")] + public class RGBAPackerValues : ScriptableObject + { + [SerializeField] public Texture2D rChannelTexture; + [SerializeField] public bool rChannelDefaultWhite = false; + [SerializeField] public Texture2D gChannelTexture; + [SerializeField] public bool gChannelDefaultWhite = false; + [SerializeField] public Texture2D bChannelTexture; + [SerializeField] public bool bChannelDefaultWhite = false; + [SerializeField] public Texture2D aChannelTexture; + [SerializeField] public bool aChannelDefaultWhite = false; + + [SerializeField] public TextureSizes textureSizes = TextureSizes._512; + [SerializeField] public FilterMode filtering = FilterMode.Bilinear; + + [System.NonSerialized] public Texture2D createdRGBATexture; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerValues.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerValues.cs.meta new file mode 100644 index 0000000..8c82c68 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerValues.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 528fe3f4f6615d447a0ee01d2fc83aba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/RGBAPackerValues.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/RenderMaterialToImageTool.cs b/Assets/Plugins/AllIn13DShader/Editor/Tools/RenderMaterialToImageTool.cs new file mode 100644 index 0000000..69f2845 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/RenderMaterialToImageTool.cs @@ -0,0 +1,44 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class RenderMaterialToImageTool + { + public static void RenderAndSaveTexture(Material targetMaterial, Texture targetTexture, float scaleSlider, string folderPath, string fileName) + { + RenderTexture renderTarget = new RenderTexture((int)(targetTexture.width * scaleSlider), + (int)(targetTexture.height * scaleSlider), 0, RenderTextureFormat.ARGB32); + Graphics.Blit(targetTexture, renderTarget, targetMaterial); + Texture2D resultTex = new Texture2D(renderTarget.width, renderTarget.height, TextureFormat.ARGB32, false); + resultTex.ReadPixels(new Rect(0, 0, renderTarget.width, renderTarget.height), 0, 0); + resultTex.Apply(); + + if (!Directory.Exists(folderPath)) + { + EditorUtility.DisplayDialog("The desired Material to Image Save Path doesn't exist", + "Go to Window -> AllIn1VfxWindow and set a valid folder", "Ok"); + return; + } + + string fullPath = Path.Combine(folderPath, fileName + ".png"); + fullPath = AssetDatabase.GenerateUniqueAssetPath(fullPath); + + string correctedFileName = fullPath.Replace(folderPath, string.Empty); + + fullPath = EditorUtility.SaveFilePanel("Save Render Image", folderPath, fileName, "png"); + + byte[] bytes = resultTex.EncodeToPNG(); + File.WriteAllBytes(fullPath, bytes); + AssetDatabase.ImportAsset(fullPath); + AssetDatabase.Refresh(); + GameObject.DestroyImmediate(resultTex); + + EditorUtils.PingPath(fullPath); + + EditorUtils.ShowNotification("Render Image saved to: " + fullPath + " with scale: " + scaleSlider + + " (it can be changed in Tools -> AllIn1 -> 3DShaderWindow)"); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/RenderMaterialToImageTool.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/RenderMaterialToImageTool.cs.meta new file mode 100644 index 0000000..a8798b6 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/RenderMaterialToImageTool.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 543c3fdde2688b6428241f7df95a671a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/RenderMaterialToImageTool.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders.meta new file mode 100644 index 0000000..f94ae17 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 16946208f34cf7840a03e45bed00c4a0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderFractalNoise.shader b/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderFractalNoise.shader new file mode 100644 index 0000000..1e4ab77 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderFractalNoise.shader @@ -0,0 +1,155 @@ +Shader "AllIn13DShader/Noises/AllIn13DShaderFractalNoise" +{ + Properties + { + _ScaleX("Scale X", Range(0.1, 100)) = 4 + _ScaleY("Scale Y", Range(0.1, 100)) = 4 + _StartBand("Start Band", Range(0.1, 10)) = 1 + _EndBand("End Band", Range(0.1, 10)) = 8 + _Offset("Offset", Range(-100, 100)) = 1 + _Contrast("Contrast", Range (0, 10)) = 1 + _Brightness("Brightness", Range (-1, 1)) = 0 + [MaterialToggle] _Invert("Invert?", Float) = 0 + [MaterialToggle] _Fractal("Fractal?", Float) = 0 + } + SubShader + { + Cull Off + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + #include "UnityCG.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + }; + + v2f vert(appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = v.uv; + return o; + } + + float4 Mod289(float4 x) + { + return x - floor(x * (1.0 / 289.0)) * 289.0; + } + + float4 PermuteFloat4(float4 x) + { + return Mod289(((x * 34.0) + 1.0) * x); + } + + float4 TaylorInvSqrt(float4 r) + { + return 1.79284291400159 - 0.85373472095314 * r; + } + + float2 FadeFloat2(float2 t) + { + return t * t * t * (t * (t * 6.0 - 15.0) + 10.0); + } + + float3 FadeFloat3(float3 t) + { + return t * t * t * (t * (t * 6.0 - 15.0) + 10.0); + } + + float PerlinNoise(float2 P, float2 rep) + { + float4 Pi = floor(P.xyxy) + float4(0.0, 0.0, 1.0, 1.0); + float4 Pf = frac(P.xyxy) - float4(0.0, 0.0, 1.0, 1.0); + Pi = fmod(Pi, rep.xyxy); + Pi = Mod289(Pi); + float4 ix = Pi.xzxz; + float4 iy = Pi.yyww; + float4 fx = Pf.xzxz; + float4 fy = Pf.yyww; + + float4 i = PermuteFloat4(PermuteFloat4(ix) + iy); + + float4 gx = frac(i * (1.0 / 41.0)) * 2.0 - 1.0; + float4 gy = abs(gx) - 0.5; + float4 tx = floor(gx + 0.5); + gx = gx - tx; + + float2 g00 = float2(gx.x, gy.x); + float2 g10 = float2(gx.y, gy.y); + float2 g01 = float2(gx.z, gy.z); + float2 g11 = float2(gx.w, gy.w); + + float4 norm = TaylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); + g00 *= norm.x; + g01 *= norm.y; + g10 *= norm.z; + g11 *= norm.w; + + float n00 = dot(g00, float2(fx.x, fy.x)); + float n10 = dot(g10, float2(fx.y, fy.y)); + float n01 = dot(g01, float2(fx.z, fy.z)); + float n11 = dot(g11, float2(fx.w, fy.w)); + + float2 fade_xy = FadeFloat2(Pf.xy); + float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x); + float n_xy = lerp(n_x.x, n_x.y, fade_xy.y); + return 2.3 * n_xy; + } + + float NoiseManger(float2 st, int scale_x, int scale_y, float seed, float scale_value, int start_band, int end_band, float persistance, int type) + { + float accum = 0.0; + float sx = scale_x; + float sy = scale_y; + float sv = scale_value; + for (int i = 1; i <= 16; i += 1) + { + if (i >= start_band && i <= end_band) + { + if (type == 0) + accum += (PerlinNoise(float3(st.x * sx, st.y * sy, seed), float3(sx, sy, 1000.)) * 0.5 + 0.5) * sv; + else + accum += abs(PerlinNoise(float3(st.x * sx, st.y * sy, seed), float3(sx, sy, 1000.))) * sv; + sv *= persistance; + seed += 1.; + } + sx *= 2.0; + sy *= 2.0; + } + + if (type == 2) + accum = 1 - accum; + + return accum; + } + + half _ScaleX, _ScaleY, _Offset, _StartBand, _EndBand, _Fractal, _Invert, _Contrast, _Brightness; + + fixed4 frag(v2f i) : SV_Target + { + i.uv.x += _Offset * 1.3234; + i.uv.y += _Offset * 0.8734; + + float result = NoiseManger(i.uv, _ScaleX, _ScaleY, _Offset * 9745, 0.7, _StartBand, _EndBand, 0.5, 1 - _Fractal); + if(_Invert) result = 1 - result; + result = saturate((result - 0.5) * _Contrast + 0.5 + _Brightness); + + return half4(result, result, result, 1); + } + ENDCG + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderFractalNoise.shader.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderFractalNoise.shader.meta new file mode 100644 index 0000000..4c61fda --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderFractalNoise.shader.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: 5ad3a3d3df8cd5747b9956fe00a3ed7b +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderFractalNoise.shader + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderWorleyNoise.shader b/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderWorleyNoise.shader new file mode 100644 index 0000000..dd2051f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderWorleyNoise.shader @@ -0,0 +1,234 @@ +Shader "AllIn13DShader/Noises/AllIn13DShaderWorleyNoise" +{ + Properties + { + _ScaleX("Scale X", Range(0.1, 100)) = 10 + _ScaleY("Scale Y", Range(0.1, 100)) = 10 + _Jitter("Jitter", Range(0.0, 2.0)) = 1 + _NoiseType("Noise Type", Range(0.0, 4.0)) = 0 + _Offset("Offset", Range(-100, 100)) = 1 + _Contrast("Contrast", Range (0, 10)) = 1 + _Brightness("Brightness", Range (-1, 1)) = 0 + [MaterialToggle] _Invert("Invert?", Float) = 0 + } + SubShader + { + Cull Off + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + #include "UnityCG.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + }; + + v2f vert(appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = v.uv; + return o; + } + + float3 Mod(float3 x, float y) + { + return x - y * floor(x / y); + } + + float3 Mod3(float3 x, float3 y) + { + return x - y * floor(x / y); + } + + float3 Permute(float3 x) + { + return Mod((34.0 * x + 1.0) * x, 289.0); + } + + float3 Distance(float3 x, float3 y, float3 z, bool manhattanDistance) + { + return manhattanDistance ? abs(x) + abs(y) + abs(z) : (x * x + y * y + z * z); + } + + float2 WorleyNoise(float3 P, float3 rep, float jitter, bool manhattanDistance) + { + float K = 0.142857142857; + float Ko = 0.428571428571; + float K2 = 0.020408163265306; + float Kz = 0.166666666667; + float Kzo = 0.416666666667; + + float3 Pi = Mod3(floor(P), rep); + float3 Pf = frac(P) - 0.5; + + float3 Pfx = Pf.x + float3(1.0, 0.0, -1.0); + float3 Pfy = Pf.y + float3(1.0, 0.0, -1.0); + float3 Pfz = Pf.z + float3(1.0, 0.0, -1.0); + + float3 p = Permute(Mod(Pi.x + float3(-1.0, 0.0, 1.0), rep.x)); + float3 p1 = Permute(Mod(p + Pi.y - 1.0, rep.y)); + float3 p2 = Permute(Mod(p + Pi.y, rep.y)); + float3 p3 = Permute(Mod(p + Pi.y + 1.0, rep.y)); + + float3 p11 = Permute(p1 + Pi.z - 1.0); + float3 p12 = Permute(p1 + Pi.z); + float3 p13 = Permute(p1 + Pi.z + 1.0); + + float3 p21 = Permute(p2 + Pi.z - 1.0); + float3 p22 = Permute(p2 + Pi.z); + float3 p23 = Permute(p2 + Pi.z + 1.0); + + float3 p31 = Permute(p3 + Pi.z - 1.0); + float3 p32 = Permute(p3 + Pi.z); + float3 p33 = Permute(p3 + Pi.z + 1.0); + + float3 ox11 = frac(p11 * K) - Ko; + float3 oy11 = Mod(floor(p11 * K), 7.0) * K - Ko; + float3 oz11 = floor(p11 * K2) * Kz - Kzo; + + float3 ox12 = frac(p12 * K) - Ko; + float3 oy12 = Mod(floor(p12 * K), 7.0) * K - Ko; + float3 oz12 = floor(p12 * K2) * Kz - Kzo; + + float3 ox13 = frac(p13 * K) - Ko; + float3 oy13 = Mod(floor(p13 * K), 7.0) * K - Ko; + float3 oz13 = floor(p13 * K2) * Kz - Kzo; + + float3 ox21 = frac(p21 * K) - Ko; + float3 oy21 = Mod(floor(p21 * K), 7.0) * K - Ko; + float3 oz21 = floor(p21 * K2) * Kz - Kzo; + + float3 ox22 = frac(p22 * K) - Ko; + float3 oy22 = Mod(floor(p22 * K), 7.0) * K - Ko; + float3 oz22 = floor(p22 * K2) * Kz - Kzo; + + float3 ox23 = frac(p23 * K) - Ko; + float3 oy23 = Mod(floor(p23 * K), 7.0) * K - Ko; + float3 oz23 = floor(p23 * K2) * Kz - Kzo; + + float3 ox31 = frac(p31 * K) - Ko; + float3 oy31 = Mod(floor(p31 * K), 7.0) * K - Ko; + float3 oz31 = floor(p31 * K2) * Kz - Kzo; + + float3 ox32 = frac(p32 * K) - Ko; + float3 oy32 = Mod(floor(p32 * K), 7.0) * K - Ko; + float3 oz32 = floor(p32 * K2) * Kz - Kzo; + + float3 ox33 = frac(p33 * K) - Ko; + float3 oy33 = Mod(floor(p33 * K), 7.0) * K - Ko; + float3 oz33 = floor(p33 * K2) * Kz - Kzo; + + float3 dx11 = Pfx + jitter * ox11; + float3 dy11 = Pfy.x + jitter * oy11; + float3 dz11 = Pfz.x + jitter * oz11; + + float3 dx12 = Pfx + jitter * ox12; + float3 dy12 = Pfy.x + jitter * oy12; + float3 dz12 = Pfz.y + jitter * oz12; + + float3 dx13 = Pfx + jitter * ox13; + float3 dy13 = Pfy.x + jitter * oy13; + float3 dz13 = Pfz.z + jitter * oz13; + + float3 dx21 = Pfx + jitter * ox21; + float3 dy21 = Pfy.y + jitter * oy21; + float3 dz21 = Pfz.x + jitter * oz21; + + float3 dx22 = Pfx + jitter * ox22; + float3 dy22 = Pfy.y + jitter * oy22; + float3 dz22 = Pfz.y + jitter * oz22; + + float3 dx23 = Pfx + jitter * ox23; + float3 dy23 = Pfy.y + jitter * oy23; + float3 dz23 = Pfz.z + jitter * oz23; + + float3 dx31 = Pfx + jitter * ox31; + float3 dy31 = Pfy.z + jitter * oy31; + float3 dz31 = Pfz.x + jitter * oz31; + + float3 dx32 = Pfx + jitter * ox32; + float3 dy32 = Pfy.z + jitter * oy32; + float3 dz32 = Pfz.y + jitter * oz32; + + float3 dx33 = Pfx + jitter * ox33; + float3 dy33 = Pfy.z + jitter * oy33; + float3 dz33 = Pfz.z + jitter * oz33; + + float3 d11 = Distance(dx11, dy11, dz11, manhattanDistance); + float3 d12 = Distance(dx12, dy12, dz12, manhattanDistance); + float3 d13 = Distance(dx13, dy13, dz13, manhattanDistance); + float3 d21 = Distance(dx21, dy21, dz21, manhattanDistance); + float3 d22 = Distance(dx22, dy22, dz22, manhattanDistance); + float3 d23 = Distance(dx23, dy23, dz23, manhattanDistance); + float3 d31 = Distance(dx31, dy31, dz31, manhattanDistance); + float3 d32 = Distance(dx32, dy32, dz32, manhattanDistance); + float3 d33 = Distance(dx33, dy33, dz33, manhattanDistance); + + float3 d1a = min(d11, d12); + d12 = max(d11, d12); + d11 = min(d1a, d13); + d13 = max(d1a, d13); + d12 = min(d12, d13); + float3 d2a = min(d21, d22); + d22 = max(d21, d22); + d21 = min(d2a, d23); + d23 = max(d2a, d23); + d22 = min(d22, d23); + float3 d3a = min(d31, d32); + d32 = max(d31, d32); + d31 = min(d3a, d33); + d33 = max(d3a, d33); + d32 = min(d32, d33); + float3 da = min(d11, d21); + d21 = max(d11, d21); + d11 = min(da, d31); + d31 = max(da, d31); + d11.xy = (d11.x < d11.y) ? d11.xy : d11.yx; + d11.xz = (d11.x < d11.z) ? d11.xz : d11.zx; + d12 = min(d12, d21); + d12 = min(d12, d22); + d12 = min(d12, d31); + d12 = min(d12, d32); + d11.yz = min(d11.yz, d12.xy); + d11.y = min(d11.y, d12.z); + d11.y = min(d11.y, d11.z); + return sqrt(d11.xy); + } + + half _ScaleX, _ScaleY, _Jitter, _NoiseType, _Offset, _Fractal, _Invert, _Contrast, _Brightness; + + fixed4 frag(v2f i) : SV_Target + { + float2 s = float2(_ScaleX, _ScaleY); + float2 f = WorleyNoise(float3(i.uv * s, _Offset), float3(s, 1000), _Jitter, false) * 0.5; + + //Add if for each Type + float result = 0; + if (_NoiseType < 0.1) result = f.x; //F1 - Voronoi + else if (_NoiseType < 1.1) result = f.y; //F2 - Cells 1 + else if (_NoiseType < 2.1) result = f.y - f.x; //Distance Sub - Cells 2 + else if (_NoiseType < 3.1) result = f.x * f.y; //Distance Mul - Water Voronoi + else if (_NoiseType < 4.1) result = 1 - f.x; //One Minus F - Cellular Noise + + if (_Invert) result = 1 - result; + result = saturate((result - 0.5) * _Contrast + 0.5 + _Brightness); + + return half4(result, result, result, 1); + } + ENDCG + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderWorleyNoise.shader.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderWorleyNoise.shader.meta new file mode 100644 index 0000000..26fa185 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderWorleyNoise.shader.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: e8cc5605d565f314e941622c9473162a +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/Shaders/AllIn13DShaderWorleyNoise.shader + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorTool.cs b/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorTool.cs new file mode 100644 index 0000000..04375d1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorTool.cs @@ -0,0 +1,306 @@ +using System; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class TextureEditorTool + { + public Texture2D editorTexInput; + public Texture2D editorTex; + public Texture2D cleanEditorTex; + + public TextureEditorValues values; + + public void Setup() + { + EditorUtils.SetTextureReadWrite(AssetDatabase.GetAssetPath(editorTexInput), true); + + editorTex = new Texture2D(editorTexInput.width, editorTexInput.height); + editorTex.SetPixels(editorTexInput.GetPixels()); + editorTex.Apply(); + + float aspectRatio = (float)editorTex.width / (float)editorTex.height; + int width = Mathf.Min(editorTex.width, 256); + editorTex = ScaleTexture(editorTex, width, (int)(width / aspectRatio)); + + cleanEditorTex = new Texture2D(editorTex.width, editorTex.height); + cleanEditorTex.SetPixels(editorTex.GetPixels()); + cleanEditorTex.Apply(); + + values = new TextureEditorValues(); + + RecalculateEditorTexture(); + } + + //private void SetTextureReadWrite(string assetPath, bool enable) + //{ + // TextureImporter tImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; + // if (tImporter != null) + // { + // tImporter.isReadable = enable; + // tImporter.SaveAndReimport(); + // } + //} + + private Texture2D ScaleTexture(Texture2D source, int targetWidth, int targetHeight) + { + targetWidth = Mathf.ClosestPowerOfTwo(targetWidth); + targetHeight = Mathf.ClosestPowerOfTwo(targetHeight); + + Texture2D result = new Texture2D(targetWidth, targetHeight, source.format, true); + Color[] scaledPixels = result.GetPixels(0); + float incX = ((float)1 / source.width) * ((float)source.width / targetWidth); + float incY = ((float)1 / source.height) * ((float)source.height / targetHeight); + for (int px = 0; px < scaledPixels.Length; px++) scaledPixels[px] = source.GetPixelBilinear(incX * ((float)px % targetWidth), incY * (float)Mathf.Floor(px / targetWidth)); + + result.SetPixels(scaledPixels, 0); + result.Apply(); + return result; + } + + public void RecalculateEditorTexture() + { + Color[] pixels = cleanEditorTex.GetPixels(); + int texWidth = cleanEditorTex.width; + int texHeight = cleanEditorTex.height; + + ComputeImageColorFilters(pixels); + + editorTex = new Texture2D(texWidth, texHeight); + editorTex.SetPixels(pixels); + editorTex.Apply(); + } + + private void ComputeImageColorFilters(Color[] pixels) + { + float cosHsv = values.saturation * Mathf.Cos(values.hue * 3.14159265f / 180f); + float sinHsv = values.saturation * Mathf.Sin(values.hue * 3.14159265f / 180f); + + for (int i = 0; i < pixels.Length; i++) + { + pixels[i].r = Mathf.Clamp01(((pixels[i].r - 0.5f) * values.contrast) + 0.5f); + pixels[i].g = Mathf.Clamp01(((pixels[i].g - 0.5f) * values.contrast) + 0.5f); + pixels[i].b = Mathf.Clamp01(((pixels[i].b - 0.5f) * values.contrast) + 0.5f); + + pixels[i] = new Color(Mathf.Clamp01(pixels[i].r * (1 + values.brightness)), Mathf.Clamp01(pixels[i].g * (1 + values.brightness)), Mathf.Clamp01(pixels[i].b * (1 + values.brightness)), pixels[i].a); + + pixels[i].r = Mathf.Pow(Mathf.Abs(pixels[i].r), values.gamma); + pixels[i].g = Mathf.Pow(Mathf.Abs(pixels[i].g), values.gamma); + pixels[i].b = Mathf.Pow(Mathf.Abs(pixels[i].b), values.gamma); + + pixels[i].r = Mathf.Clamp01(pixels[i].r * Mathf.Pow(2, values.exposure)); + pixels[i].g = Mathf.Clamp01(pixels[i].g * Mathf.Pow(2, values.exposure)); + pixels[i].b = Mathf.Clamp01(pixels[i].b * Mathf.Pow(2, values.exposure)); + + pixels[i] *= values.editorColorTint; + + Color hueShiftColor = pixels[i]; + hueShiftColor.r = Mathf.Clamp01((.299f + .701f * cosHsv + .168f * sinHsv) * pixels[i].r + (.587f - .587f * cosHsv + .330f * sinHsv) * pixels[i].g + (.114f - .114f * cosHsv - .497f * sinHsv) * pixels[i].b); + hueShiftColor.g = Mathf.Clamp01((.299f - .299f * cosHsv - .328f * sinHsv) * pixels[i].r + (.587f + .413f * cosHsv + .035f * sinHsv) * pixels[i].g + (.114f - .114f * cosHsv + .292f * sinHsv) * pixels[i].b); + hueShiftColor.b = Mathf.Clamp01((.299f - .3f * cosHsv + 1.25f * sinHsv) * pixels[i].r + (.587f - .588f * cosHsv - 1.05f * sinHsv) * pixels[i].g + (.114f + .886f * cosHsv - .203f * sinHsv) * pixels[i].b); + pixels[i] = hueShiftColor; + + if (values.invert) pixels[i] = new Color(1 - pixels[i].r, 1 - pixels[i].g, 1 - pixels[i].b, pixels[i].a); + + if (values.greyscale || values.fullWhite || values.alphaGreyscale) + { + float greyScale = pixels[i].r * 0.59f + pixels[i].g * 0.3f + pixels[i].b * 0.11f; + + if (values.fullWhite) pixels[i] = new Color(1, 1, 1, greyScale); + else if (values.greyscale) pixels[i] = new Color(greyScale, greyScale, greyScale, pixels[i].a); + + if (values.alphaGreyscale) pixels[i] = new Color(pixels[i].r, pixels[i].g, pixels[i].b, greyScale); + } + + if (values.alphaIsOne) pixels[i] = new Color(pixels[i].r, pixels[i].g, pixels[i].b, 1f); + + if (values.blackBackground) + { + if (pixels[i].a < 0.05f) pixels[i] = new Color(pixels[i].a, pixels[i].a, pixels[i].a, 1); + else pixels[i] = new Color(pixels[i].r, pixels[i].g, pixels[i].b, 1); + } + } + } + + public void FlipEditorTexture(bool isHorizontal) + { + Color[] pixels = editorTex.GetPixels(); + Color[] pixelsClean = cleanEditorTex.GetPixels(); + int texWidth = editorTex.width; + int texHeight = editorTex.height; + + if (isHorizontal) + { + pixels = FlipHorizontal(pixels, texWidth, texHeight); + pixelsClean = FlipHorizontal(pixelsClean, texWidth, texHeight); + values.isFlipHorizontal = !values.isFlipHorizontal; + } + else + { + pixels = FlipVertical(pixels, texWidth, texHeight); + pixelsClean = FlipVertical(pixelsClean, texWidth, texHeight); + values.isFlipVertical = !values.isFlipVertical; + } + + editorTex = new Texture2D(texWidth, texHeight); + editorTex.SetPixels(pixels); + editorTex.Apply(); + cleanEditorTex = new Texture2D(texWidth, texHeight); + cleanEditorTex.SetPixels(pixelsClean); + cleanEditorTex.Apply(); + } + + private Color[] FlipHorizontal(Color[] pixels, int width, int height) + { + Color[] outputPixels = new Color[pixels.Length]; + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + int i1 = GetPixelIndex(x, y, width); + int i2 = GetPixelIndex(width - 1 - x, y, width); + outputPixels[i1] = pixels[i2]; + } + } + + return outputPixels; + } + + private Color[] FlipVertical(Color[] pixels, int width, int height) + { + Color[] outputPixels = new Color[pixels.Length]; + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + int i1 = GetPixelIndex(x, y, width); + int i2 = GetPixelIndex(x, height - 1 - y, width); + outputPixels[i1] = pixels[i2]; + } + } + + return outputPixels; + } + + private int GetPixelIndex(int x, int y, int width) + { + return y * width + x; + } + + public void RotateEditorTextureLeft() + { + Color[] pixels = editorTex.GetPixels(); + Color[] pixelsClean = cleanEditorTex.GetPixels(); + int texWidth = editorTex.width; + int texHeight = editorTex.height; + + pixels = RotateClockWise(pixels, texWidth, texHeight); + pixelsClean = RotateClockWise(pixelsClean, texWidth, texHeight); + + editorTex = new Texture2D(texHeight, texWidth); //Width and Height get swapped to account for rotation + editorTex.SetPixels(pixels); + editorTex.Apply(); + cleanEditorTex = new Texture2D(texHeight, texWidth); //Width and Height get swapped to account for rotation + cleanEditorTex.SetPixels(pixelsClean); + cleanEditorTex.Apply(); + + values.rotationAmount = (values.rotationAmount + 1) % 4; + } + + public Color[] RotateClockWise(Color[] pixels, int width, int height) + { + Color[] outputPixels = new Color[pixels.Length]; + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + int i1 = GetPixelIndex(x, height - y - 1, width); + int i2 = GetPixelIndex(y, x, height); + outputPixels[i2] = pixels[i1]; + } + } + + return outputPixels; + } + + private void ComputeFinalTexture() + { + Color[] pixels; + int texWidth, texHeight; + + for (int i = 0; i < values.rotationAmount; i++) + { + texWidth = editorTexInput.width; + texHeight = editorTexInput.height; + pixels = editorTexInput.GetPixels(); + pixels = RotateClockWise(pixels, texWidth, texHeight); + editorTexInput = new Texture2D(texHeight, texWidth); + editorTexInput.SetPixels(pixels); + editorTexInput.Apply(); + } + + pixels = editorTexInput.GetPixels(); + texWidth = editorTexInput.width; + texHeight = editorTexInput.height; + if (values.isFlipHorizontal) + { + pixels = FlipHorizontal(pixels, texWidth, texHeight); + } + if (values.isFlipVertical) + { + pixels = FlipVertical(pixels, texWidth, texHeight); + } + + ComputeImageColorFilters(pixels); + editorTexInput = new Texture2D(texWidth, texHeight); + editorTexInput.SetPixels(pixels); + editorTexInput.Apply(); + + if (Math.Abs(values.exportScale - 1f) > 0.05f) + { + editorTexInput = ScaleTexture(editorTexInput, (int)(texWidth * values.exportScale), (int)(texHeight * values.exportScale)); + } + } + + public void SaveAsPNG() + { + string fullPath = AssetDatabase.GetAssetPath(editorTexInput); + string path = fullPath.Replace(Path.GetFileName(fullPath), ""); + + fullPath = AssetDatabase.GenerateUniqueAssetPath(fullPath); + + string fileName = fullPath.Replace(path, ""); + fileName = fileName.Replace(".png", ""); + fullPath = EditorUtility.SaveFilePanel("Save Image", path, fileName, "png"); + if (fullPath.Length == 0) + { + return; + } + + string pingPath = fullPath; + + ComputeFinalTexture(); + + byte[] bytes = editorTexInput.EncodeToPNG(); + File.WriteAllBytes(pingPath, bytes); + AssetDatabase.ImportAsset(pingPath); + AssetDatabase.Refresh(); + EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(pingPath, typeof(Texture))); + + EditorUtils.ShowNotification("Edited Image saved to: " + fullPath); + + editorTexInput = null; + editorTex = null; + cleanEditorTex = null; + + SetTextureEditorDefaultValues(); + } + + private void SetTextureEditorDefaultValues() + { + values.SetDefault(); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorTool.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorTool.cs.meta new file mode 100644 index 0000000..d786095 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorTool.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 0d7236daca41e9541a940c4cb32fca47 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorTool.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorValues.cs b/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorValues.cs new file mode 100644 index 0000000..c4170dd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorValues.cs @@ -0,0 +1,52 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + public class TextureEditorValues + { + public Color editorColorTint; + public float brightness; + public float contrast; + public float gamma; + public float exposure; + public float saturation; + public float hue; + public bool invert; + public bool greyscale; + public bool fullWhite; + public bool blackBackground; + public bool alphaGreyscale; + public bool alphaIsOne; + public bool showOriginalImage; + public bool isFlipHorizontal; + public bool isFlipVertical; + public int rotationAmount; + public float exportScale; + + public TextureEditorValues() + { + SetDefault(); + } + + public void SetDefault() + { + editorColorTint = Color.white; + brightness = 0f; + contrast = 1f; + gamma = 1f; + exposure = 0f; + saturation = 1f; + hue = 0f; + invert = false; + greyscale = false; + fullWhite = false; + blackBackground = false; + alphaGreyscale = false; + showOriginalImage = false; + isFlipHorizontal = false; + isFlipVertical = false; + rotationAmount = 0; + exportScale = 1f; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorValues.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorValues.cs.meta new file mode 100644 index 0000000..41248cd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorValues.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 32d12b4e3bfea4e42bca81b1abfb8e7b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Tools/TextureEditorValues.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings.meta b/Assets/Plugins/AllIn13DShader/Editor/URP Settings.meta new file mode 100644 index 0000000..523cdf8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 21c3c411c1a1d7a448480e1579686216 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPDefinesFileCreator.cs b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPDefinesFileCreator.cs new file mode 100644 index 0000000..457fba0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPDefinesFileCreator.cs @@ -0,0 +1,49 @@ +using System; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public static class URPDefinesFileCreator + { + public static void CreateFile(URPSettings urpSettings, URPSettingsUserPref userPref) + { + string urpDefinesFilePath = Path.Combine(GlobalConfiguration.instance.RootPluginPath, "Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl"); + string hlslLibraryTemplatePath = Path.Combine(GlobalConfiguration.instance.RootPluginPath, "Editor/Templates/HLSLLibrary_Template.allIn13DTemplate"); + + if (!File.Exists(urpDefinesFilePath)) + { + Debug.LogError("URP defines file not found"); + return; + } + + if (!File.Exists(hlslLibraryTemplatePath)) + { + Debug.LogError("HLSL library template not found"); + return; + } + + string fileText = File.ReadAllText(hlslLibraryTemplatePath); + string content = string.Empty; + for (int i = 0; i < userPref.preferences.Length; i++) + { + if (userPref.preferences[i].enabled) + { + string line = string.Format(Constants.DEFINE_LINE_FORMAT, urpSettings.configs[i].shaderDefine); + + content += line; + content += "\n"; + } + } + + fileText = fileText.Replace("", "ALLIN13DSHADER_FEATURESURP_DEFINES"); + fileText = fileText.Replace("", content); + + fileText = EditorUtils.UnifyEOL(fileText); + File.WriteAllText(urpDefinesFilePath, fileText); + + EditorUtility.SetDirty(userPref); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPDefinesFileCreator.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPDefinesFileCreator.cs.meta new file mode 100644 index 0000000..20a045b --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPDefinesFileCreator.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 7cb7da377e96d0a4eb22d4e1096b0abf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPDefinesFileCreator.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureConfig.cs b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureConfig.cs new file mode 100644 index 0000000..e435dc1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureConfig.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [System.Serializable] + public class URPFeatureConfig + { + public string shaderDefine; + public bool defaultValue; + [TextArea] public string displayName; + [TextArea] public string tooltip; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureConfig.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureConfig.cs.meta new file mode 100644 index 0000000..13c273a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureConfig.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 9acfe1c62a8952a478ff077e760990fb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureConfig.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureUserPref.cs b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureUserPref.cs new file mode 100644 index 0000000..7b71865 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureUserPref.cs @@ -0,0 +1,20 @@ +namespace AllIn13DShader +{ + [System.Serializable] + public class URPFeatureUserPref + { + public string id; + public bool enabled; + + public URPFeatureUserPref(URPFeatureConfig config) + { + Init(config); + } + + public void Init(URPFeatureConfig config) + { + this.id = config.shaderDefine; + this.enabled = config.defaultValue; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureUserPref.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureUserPref.cs.meta new file mode 100644 index 0000000..277f10f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureUserPref.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: fa8bf848a0315b948bb27aec4c2cd886 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPFeatureUserPref.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.asset b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.asset new file mode 100644 index 0000000..6d76481 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.asset @@ -0,0 +1,78 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a34d35cf36d0b9649b45a5ba18657d1f, type: 3} + m_Name: URPSettings + m_EditorClassIdentifier: AllIn13DShaderAssemebly.Editor::AllIn13DShader.URPSettings + configs: + - shaderDefine: ALLIN1_GPU_INSTANCING_SUPPORT + defaultValue: 1 + displayName: GPU Instancing Support + tooltip: Enables GPU Instancing for better performance when rendering many identical + objects + - shaderDefine: ALLIN1_DOTS_INSTANCING_SUPPORT + defaultValue: 0 + displayName: Entities Graphics Instancing Support (and GPU Resident Drawer) + tooltip: Supports Unity Entities Graphics instancing for DOTS-based projects + and GPU Resident Drawer + - shaderDefine: ALLIN1_FOG_SUPPORT + defaultValue: 1 + displayName: Fog Support + tooltip: Unity fog system integration for atmospheric effects + - shaderDefine: ALLIN1_LIGHTMAPS_SUPPORT + defaultValue: 1 + displayName: Lightmaps Support + tooltip: Enables baked lightmap support for static lighting + - shaderDefine: ALLIN1_ADDITIONAL_LIGHTS_SUPPORT + defaultValue: 1 + displayName: Additional Lights Support + tooltip: Support for additional real-time lights beyond main directional light + - shaderDefine: ALLIN1_CAST_SHADOWS_SUPPORT + defaultValue: 1 + displayName: Cast Shadows Support + tooltip: Enables shadow casting from materials using this shader + - shaderDefine: ALLIN1_SHADOW_MASK_SUPPORT + defaultValue: 1 + displayName: Shadow Mask Support + tooltip: Mixed lighting shadowmask support for hybrid lighting setups + - shaderDefine: ALLIN1_FORWARD_PLUS_SUPPORT_UNITY6 + defaultValue: 1 + displayName: Forward+ Support (Unity 6+) + tooltip: Forward+ rendering path support (Unity 6+ only) + - shaderDefine: ALLIN1_REFLECTIONS_PROBES_SUPPORT_UNITY6 + defaultValue: 0 + displayName: Reflection Probes Blending Support (Unity 6+) + tooltip: Probe blending support (Unity 6+ only, if you aren't using more than + 1 probe you can disable this) + - shaderDefine: ALLIN1_ADAPTATIVE_PROBE_VOLUMES_UNITY6 + defaultValue: 1 + displayName: Adaptative Probe Volumes (Unity 6+) + tooltip: Adaptative Probe Volumes support (Unity 6+ only) + - shaderDefine: ALLIN1_SSO_SUPPORT + defaultValue: 1 + displayName: Screen Space Ambient Occlusion + tooltip: Screen Space Ambient Occlusion integration + - shaderDefine: ALLIN1_LIGHT_LAYERS_SUPPORT + defaultValue: 0 + displayName: Light Layers Support + tooltip: Unity light layer system support (for selective lighting) + - shaderDefine: ALLIN1_DECALS_SUPPORT + defaultValue: 0 + displayName: Decals Support + tooltip: Unity decals system support + - shaderDefine: ALLIN1_LIGHT_COOKIES_SUPPORT + defaultValue: 0 + displayName: 'Light Cookies ' + tooltip: Unity Light Cookies system support + - shaderDefine: ALLIN1_LODCROSSFADE_SUPPORT + defaultValue: 0 + displayName: LOD Cross Fade + tooltip: LOD Cross Fade support diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.asset.meta b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.asset.meta new file mode 100644 index 0000000..d27e1e1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.asset.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: cbb6de4f9322b024abf937982abd31f7 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.asset + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.cs b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.cs new file mode 100644 index 0000000..12c27e3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.cs @@ -0,0 +1,28 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [CreateAssetMenu(menuName = "AllIn13D/URP Settings")] + public class URPSettings : ScriptableObject + { + public const string ASSET_NAME = "URPSettings"; + + public URPFeatureConfig[] configs; + + public URPFeatureConfig FindConfigByID(string id) + { + URPFeatureConfig res = null; + + for(int i = 0; i < configs.Length; i++) + { + if(configs[i].shaderDefine == id) + { + res = configs[i]; + break; + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.cs.meta new file mode 100644 index 0000000..b44d135 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: a34d35cf36d0b9649b45a5ba18657d1f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettings.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettingsUserPref.cs b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettingsUserPref.cs new file mode 100644 index 0000000..12237d5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettingsUserPref.cs @@ -0,0 +1,94 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class URPSettingsUserPref : ScriptableObject + { + public const string ASSET_NAME = "URPSettingsUserPref"; + + public URPFeatureUserPref[] preferences; + + public void Init(URPSettings urpSettings) + { + preferences = new URPFeatureUserPref[urpSettings.configs.Length]; + + for(int i = 0; i < urpSettings.configs.Length; i++) + { + preferences[i] = new URPFeatureUserPref(urpSettings.configs[i]); + } + } + + public static URPSettingsUserPref InitIfNeeded() + { + URPSettingsUserPref res = null; + + res = EditorUtils.FindAsset(ASSET_NAME); + + if (res == null) + { + URPSettings urpSettings = EditorUtils.FindAsset(URPSettings.ASSET_NAME); + + res = ScriptableObject.CreateInstance(); + res.Init(urpSettings); + + string filePath = Path.Combine(GlobalConfiguration.instance.GlobalConfigFolderPath, ASSET_NAME + ".asset"); + AssetDatabase.CreateAsset(res, filePath); + + URPDefinesFileCreator.CreateFile(urpSettings, res); + + AssetDatabase.Refresh(); + } + else + { + URPSettings urpSettings = EditorUtils.FindAsset(URPSettings.ASSET_NAME); + + if (res.preferences.Length != urpSettings.configs.Length) + { + res.MatchWithURPSettings(urpSettings); + } + } + + return res; + } + + public void MatchWithURPSettings(URPSettings urpSettings) + { + for(int i = preferences.Length - 1; i >= 0; i--) + { + URPFeatureConfig urpFeatureConfig = urpSettings.FindConfigByID(preferences[i].id); + if(urpFeatureConfig == null) + { + ArrayUtility.RemoveAt(ref preferences, i); + } + } + + for(int i = 0; i < urpSettings.configs.Length; i++) + { + URPFeatureUserPref userPref = FindPreferenceByID(urpSettings.configs[i].shaderDefine); + + if(userPref == null) + { + ArrayUtility.Add(ref preferences, new URPFeatureUserPref(urpSettings.configs[i])); + } + } + } + + public URPFeatureUserPref FindPreferenceByID(string id) + { + URPFeatureUserPref res = null; + + for(int i = 0; i < preferences.Length; i++) + { + if (preferences[i].id == id) + { + res = preferences[i]; + break; + } + } + + return res; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettingsUserPref.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettingsUserPref.cs.meta new file mode 100644 index 0000000..a08aef1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettingsUserPref.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 18225d53cd7719c49b6df4340a1549ff +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/URP Settings/URPSettingsUserPref.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/URPConfigurator.cs b/Assets/Plugins/AllIn13DShader/Editor/URPConfigurator.cs new file mode 100644 index 0000000..677e2bc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URPConfigurator.cs @@ -0,0 +1,294 @@ +using System.Collections.Generic; +using System.Reflection; +using UnityEditor; +using UnityEngine; +using UnityEngine.Rendering; +using UnityEditor.Rendering; +using System.IO; + + +#if ALLIN13DSHADER_URP + +using UnityEditor.Rendering.Universal; +#if UNITY_6000_0_OR_NEWER +using UnityEngine.Rendering.Universal; +#else +using UnityEngine.Experimental.Rendering.Universal; +using UnityEngine.Rendering.Universal; +#endif + +#endif + +namespace AllIn13DShader +{ + public static class URPConfigurator + { +#if ALLIN13DSHADER_URP + + private const string OUTLINE_PASS_NAME = "OutlinePass"; + private const string OUTLINE_OPAQUE_RENDER_FEATURE_NAME = "Render Feature - Outline Opaque"; + private const string OUTLINE_TRANSPARENT_RENDER_FEATURE_NAME = "Render Feature - Outline Transparent"; + + private const string KEY_PIPELINE_PACKAGE_REMOVED = "ALLIN13DSHADER_PIPELINE_PACKAGE_REMOVED_KEY"; + + public static bool IsURPCorrectlyConfigured() + { + bool res = true; + if(GraphicsSettings.currentRenderPipeline == null) + { + res = false; + } + + return res; + } + + public static void Configure(bool forceConfigure = false) + { + RenderPipelineAsset pipeline = GraphicsSettings.currentRenderPipeline; + + if(pipeline != null) + { + string guid; + long localID; + AssetDatabase.TryGetGUIDAndLocalFileIdentifier(pipeline, out guid, out localID); + + if (forceConfigure) + { + ConfigureURPAccepted(pipeline); + + GlobalConfiguration.instance.URPConfiguredFirstTime = true; + } + else + { + if (!GlobalConfiguration.instance.URPConfiguredFirstTime) + { + bool configureAccepted = EditorUtility.DisplayDialog("AllIn13DShader automatic configuration", "Do you want to automatically configure this URP project to work with all 3D-Shader?\n" + + "If you Cancel please check the Documentation:\n" + + "https://seasidestudios.gitbook.io/seaside-studios/3d-shader/urp-and-post-processing-setup", "Configure", "Cancel"); + if (configureAccepted) + { + ConfigureURPAccepted(pipeline); + } + + GlobalConfiguration.instance.URPConfiguredFirstTime = true; + } + } + } + } + + private static void ConfigureURPAccepted(RenderPipelineAsset pipeline) + { + Debug.Log("Configuring plugin to work with URP..."); + + ConfigureRenderPipeline(pipeline); + + string demoMaterialsFolder = Path.Combine(GlobalConfiguration.instance.RootPluginPath, Constants.STANDARD_EXAMPLES_MATERIALS_LOCAL_PATH); + if (AssetDatabase.IsValidFolder(demoMaterialsFolder)) + { + ConvertMaterialsFolder(demoMaterialsFolder); + } + } + + private static void CreateRenderFeatureOutline(UniversalRendererData universalRendererData, + string renderFeatureName, + RenderQueueType renderQueueType, RenderPassEvent renderPassEvent) + { + RenderObjects outlineRenderFeature = null; + bool outlineRenderFeatureFound = false; + + List rendererFeatures = universalRendererData.rendererFeatures; + foreach (ScriptableRendererFeature scriptableRendererFeature in rendererFeatures) + { + if (scriptableRendererFeature is RenderObjects) + { + RenderObjects renderObjects = (RenderObjects)scriptableRendererFeature; + string[] passNames = renderObjects.settings.filterSettings.PassNames; + + for (int i = 0; i < passNames.Length; i++) + { + if (passNames[i] == OUTLINE_PASS_NAME && renderObjects.settings.filterSettings.RenderQueueType == renderQueueType) + { + outlineRenderFeature = renderObjects; + outlineRenderFeatureFound = true; + } + } + + if (outlineRenderFeatureFound) + { + break; + } + } + } + + if (!outlineRenderFeatureFound) + { + outlineRenderFeature = RenderObjects.CreateInstance(); + outlineRenderFeature.name = renderFeatureName; + + rendererFeatures.Add(outlineRenderFeature); + + FieldInfo fieldInfoRenderFeaturesMap = typeof(UniversalRendererData).GetField("m_RendererFeatureMap", BindingFlags.Instance | BindingFlags.NonPublic); + List renderFeaturesMapList = fieldInfoRenderFeaturesMap.GetValue(universalRendererData) as List; + + string guid; + long localID; + AssetDatabase.TryGetGUIDAndLocalFileIdentifier(outlineRenderFeature, out guid, out localID); + renderFeaturesMapList.Add(localID); + + AssetDatabase.AddObjectToAsset(outlineRenderFeature, universalRendererData); + EditorUtility.SetDirty(outlineRenderFeature); + } + + outlineRenderFeature.name = renderFeatureName; + outlineRenderFeature.settings.filterSettings.RenderQueueType = renderQueueType; + outlineRenderFeature.settings.filterSettings.LayerMask = ~0; + outlineRenderFeature.settings.Event = renderPassEvent; + outlineRenderFeature.settings.filterSettings.PassNames = new string[] { OUTLINE_PASS_NAME }; + outlineRenderFeature.SetActive(true); + + + + EditorUtility.SetDirty(outlineRenderFeature); + EditorUtility.SetDirty(universalRendererData); + + FieldInfo fieldInfoRendererFeatures = typeof(UniversalRendererData).GetField("m_RendererFeatures", BindingFlags.Instance | BindingFlags.NonPublic); + fieldInfoRendererFeatures.SetValue(universalRendererData, rendererFeatures); + } + + public static void ConfigureRenderPipeline(RenderPipelineAsset renderPipelineAsset) + { + UniversalRenderPipelineAsset pipeline = renderPipelineAsset as UniversalRenderPipelineAsset; + ScriptableRenderer scriptableRenderer = pipeline.GetRenderer(0); + + FieldInfo rendererDataListFieldInfo = typeof(UniversalRenderPipelineAsset).GetField("m_RendererDataList", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); + ScriptableRendererData[] scriptableRendererDatas = rendererDataListFieldInfo.GetValue(pipeline) as ScriptableRendererData[]; + + UniversalRendererData universalRendererData = scriptableRendererDatas[0] as UniversalRendererData; + + if(universalRendererData != null) + { + Undo.RecordObject(universalRendererData, ""); + + universalRendererData.depthPrimingMode = DepthPrimingMode.Disabled; + + + CreateRenderFeatureOutline(universalRendererData: universalRendererData, renderFeatureName: OUTLINE_OPAQUE_RENDER_FEATURE_NAME, + renderQueueType: RenderQueueType.Opaque, renderPassEvent: RenderPassEvent.AfterRenderingOpaques); + + CreateRenderFeatureOutline(universalRendererData: universalRendererData, renderFeatureName: OUTLINE_TRANSPARENT_RENDER_FEATURE_NAME, + renderQueueType: RenderQueueType.Transparent, renderPassEvent: RenderPassEvent.AfterRenderingTransparents); + + EditorUtility.SetDirty(universalRendererData); + EditorUtility.SetDirty(pipeline); + AssetDatabase.SaveAssets(); + } + } + + public static void ConvertMaterialsFolder(string dirPath) + { + StandardUpgrader standardUpgrader = new StandardUpgrader("Standard"); + + DirectoryInfo dir = new DirectoryInfo(dirPath); + + List materialsPathsToConvert = new List(); + FileInfo[] files = dir.GetFiles("*.mat"); + for (int i = 0; i < files.Length; i++) + { + string materialPath = Path.Combine(dirPath, files[i].Name); + materialsPathsToConvert.Add(materialPath); + } + + for (int i = 0; i < materialsPathsToConvert.Count; i++) + { + Material mat = AssetDatabase.LoadAssetAtPath(materialsPathsToConvert[i]); + standardUpgrader.Upgrade(mat, MaterialUpgrader.UpgradeFlags.None); + } + } + + public static void CheckURPRemoved(string[] deletedAssets, bool didDomainReload) + { + bool removeUniversalForward = false; + for (int i = 0; i < deletedAssets.Length; i++) + { + removeUniversalForward = deletedAssets[i].StartsWith("Packages/com.unity.render-pipelines"); + } + + SessionState.SetBool(KEY_PIPELINE_PACKAGE_REMOVED, removeUniversalForward); + + + if (!didDomainReload && SessionState.GetBool(KEY_PIPELINE_PACKAGE_REMOVED, false)) + { + RenderPipelineChecker.RemovePipelineSymbols(); + SessionState.SetBool(KEY_PIPELINE_PACKAGE_REMOVED, false); + + Debug.LogWarning("Render pipeline package removed. Configuring AllIn13DShader..."); + } + } + + public static void AllAssetProcessed() + { + Configure(); + } + + + public static bool IsRenderPipelineAssigned() + { + bool res = GraphicsSettings.currentRenderPipeline != null; + return res; + } + + public static bool IsOutlinePassConfigured() + { + bool res = false; + + UniversalRenderPipelineAsset pipeline = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset; + ScriptableRenderer scriptableRenderer = pipeline.GetRenderer(0); + + FieldInfo rendererDataListFieldInfo = typeof(UniversalRenderPipelineAsset).GetField("m_RendererDataList", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); + ScriptableRendererData[] scriptableRendererDatas = rendererDataListFieldInfo.GetValue(pipeline) as ScriptableRendererData[]; + + UniversalRendererData universalRendererData = scriptableRendererDatas[0] as UniversalRendererData; + + List rendererFeatures = universalRendererData.rendererFeatures; + foreach (ScriptableRendererFeature scriptableRendererFeature in rendererFeatures) + { + RenderObjects renderObjects = (RenderObjects)scriptableRendererFeature; + + string[] passNames = renderObjects.settings.filterSettings.PassNames; + foreach (string passName in passNames) + { + if (passName == OUTLINE_PASS_NAME) + { + res = true; + break; + } + } + } + + return res; + } + + public static bool IsDemoMaterialsConfigured() + { + bool res = false; + + string demoMaterialsFolder = Path.Combine(GlobalConfiguration.instance.RootPluginPath, Constants.STANDARD_EXAMPLES_MATERIALS_LOCAL_PATH); + if (AssetDatabase.IsValidFolder(demoMaterialsFolder)) + { + ConvertMaterialsFolder(demoMaterialsFolder); + } + + return res; + } + + public static bool IsURPMissconfigured() + { + bool res = false; + + bool renderPipelineAssigned = GraphicsSettings.currentRenderPipeline != null; + + return res; + } +#endif + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/URPConfigurator.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/URPConfigurator.cs.meta new file mode 100644 index 0000000..dbc0a08 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/URPConfigurator.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 80f03ed0410db654a95ec1e8b07e3b73 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/URPConfigurator.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities.meta b/Assets/Plugins/AllIn13DShader/Editor/Utilities.meta new file mode 100644 index 0000000..dd0cae9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0907c03e4b80a204cb93e836a0df24f4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/AllIn1ShaderPropertyType.cs b/Assets/Plugins/AllIn13DShader/Editor/Utilities/AllIn1ShaderPropertyType.cs new file mode 100644 index 0000000..ee1eef9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/AllIn1ShaderPropertyType.cs @@ -0,0 +1,12 @@ +namespace AllIn13DShader +{ + public enum AllIn1ShaderPropertyType + { + Color, + Vector, + Float, + Range, + Texture, + Int, + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/AllIn1ShaderPropertyType.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Utilities/AllIn1ShaderPropertyType.cs.meta new file mode 100644 index 0000000..ccdc5f7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/AllIn1ShaderPropertyType.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: ec187d05b38a07248aacd485cddf8cde +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Utilities/AllIn1ShaderPropertyType.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/EditorUtils.cs b/Assets/Plugins/AllIn13DShader/Editor/Utilities/EditorUtils.cs new file mode 100644 index 0000000..218e096 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/EditorUtils.cs @@ -0,0 +1,493 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; + +namespace AllIn13DShader +{ + public static class EditorUtils + { + public static T FindAsset(string assetName) where T : Object + { + T res = null; + + string[] guids = AssetDatabase.FindAssets($"{assetName} t:{typeof(T).Name}"); + + if (guids.Length > 0) + { + string path = AssetDatabase.GUIDToAssetPath(guids[0]); + res = AssetDatabase.LoadAssetAtPath(path); + } + + return res; + } + + public static T FindAssetByName(string assetName) where T : Object + { + T res = null; + + string filter = $"t:{typeof(T)} {assetName}"; + string[] guids = AssetDatabase.FindAssets(filter); + + if (guids.Length > 0) + { + string path = AssetDatabase.GUIDToAssetPath(guids[0]); + res = (T)AssetDatabase.LoadAssetAtPath(path, typeof(T)); + } + + return res; + } + + public static List GetAllAssetsInFolder(string folderPath, string extension) where T : Object + { + List res = new List(); + + DirectoryInfo dir = new DirectoryInfo(folderPath); + List materialsPathsToConvert = new List(); + FileInfo[] files = dir.GetFiles($"*.{extension}"); + + for(int i = 0; i < files.Length; i++) + { + string materialPath = Path.Combine(folderPath, files[i].Name); + T asset = AssetDatabase.LoadAssetAtPath(materialsPathsToConvert[i]); + + res.Add(asset); + } + + return res; + } + + public static void PingPath(string assetPath) + { + Object asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture)); + if(asset != null) + { + EditorGUIUtility.PingObject(asset); + } + } + + public static void ShowNotification(string message) + { + SceneView.lastActiveSceneView.ShowNotification(new GUIContent(message)); + } + + public static void DrawThinLine() + { + DrawLine(Color.grey, 1, 3); + } + + public static void DrawLine(Color color, int thickness = 2, int padding = 10) + { + Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness)); + r.height = thickness; + r.y += padding / 2; + r.x -= 2; + r.width += 4; + EditorGUI.DrawRect(r, color); + } + + public static void SetTextureReadWrite(string assetPath, bool enable) + { + TextureImporter tImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; + if (tImporter != null) + { + tImporter.isReadable = enable; + tImporter.SaveAndReimport(); + } + } + + public static string DrawSelectorFolder(string initialPath, /*string defaultPath,*/ string label) + { + DefaultAsset folderAsset = AssetDatabase.LoadAssetAtPath(initialPath); + folderAsset = (DefaultAsset)EditorGUILayout.ObjectField(label, folderAsset, typeof(DefaultAsset), false, GUILayout.MaxWidth(500)); + + string pathCandidate = AssetDatabase.GetAssetPath(folderAsset); + + string res = initialPath; + if (Directory.Exists(pathCandidate)) + { + res = pathCandidate; + } + /* + else + { + res = defaultPath; + } + */ + + return res; + } + + public static string UnifyPathSeparators(string path) + { + string res = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); + return res; + } + + public static bool IsPathInsideTheProject(string path) + { + string pathUnifiedSeparator = UnifyPathSeparators(path); + string[] directories = pathUnifiedSeparator.Split(Path.DirectorySeparatorChar); + + bool res = directories.Contains("Assets"); + return res; + } + + public static string CutPathToStartFromAsset(string path) + { + string res = string.Empty; + + string pathUnifiedSeparator = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); + string[] directories = pathUnifiedSeparator.Split(Path.DirectorySeparatorChar); + int assetFolderIndex = -1; + for (int i = 0; i < directories.Length; i++) + { + if (assetFolderIndex < 0) + { + if (directories[i] == "Assets") + { + assetFolderIndex = i; + res = directories[i]; + + continue; + } + } + else + { + res = Path.Combine(res, directories[i]); + } + } + + return res; + } + + public static Texture SaveTextureAsPNG(string folderPath, string fileName, string prefixNotification, Texture2D texture, + FilterMode filterMode, TextureImporterType importerType, TextureWrapMode wrapMode, + bool askForLocation = true, bool generateUniqueAssetPath = true) + { + Texture res = null; + + string fileNameWithExtension = fileName + ".png"; + string path = Path.Combine(folderPath, fileNameWithExtension); + + if (generateUniqueAssetPath) + { + path = AssetDatabase.GenerateUniqueAssetPath(path); + } + + fileName = Path.GetFileNameWithoutExtension(path); + + if (askForLocation) + { + path = EditorUtility.SaveFilePanel("Save texture as PNG", folderPath, fileName, "png"); + } + + if (!string.IsNullOrEmpty(path)) + { + byte[] pngData = texture.EncodeToPNG(); + if (pngData != null) File.WriteAllBytes(path, pngData); + AssetDatabase.Refresh(); + + //string[] directories= path.Split(Path.DirectorySeparatorChar); + //bool isFolderInsideTheProject = directories[0] == "Assets"; + + if (IsPathInsideTheProject(path)) + { + string subPath = CutPathToStartFromAsset(path); + TextureImporter importer = AssetImporter.GetAtPath(subPath) as TextureImporter; + if (importer != null) + { + ShowNotification($"{prefixNotification} saved inside the project: " + subPath); + + importer.filterMode = filterMode; + importer.textureType = importerType; + importer.wrapMode = wrapMode; + + importer.SaveAndReimport(); + res = AssetDatabase.LoadAssetAtPath(subPath); + EditorGUIUtility.PingObject(res); + } + } + else + { + ShowNotification($"{prefixNotification} saved outside the project: " + path); + } + } + + return res; + } + + public static Texture2D ScaleTexture(Texture2D source, int targetWidth, int targetHeight) + { + targetWidth = Mathf.ClosestPowerOfTwo(targetWidth); + targetHeight = Mathf.ClosestPowerOfTwo(targetHeight); + + Texture2D result = new Texture2D(targetWidth, targetHeight, source.format, true); + Color[] scaledPixels = result.GetPixels(0); + float incX = ((float)1 / source.width) * ((float)source.width / targetWidth); + float incY = ((float)1 / source.height) * ((float)source.height / targetHeight); + for (int px = 0; px < scaledPixels.Length; px++) scaledPixels[px] = source.GetPixelBilinear(incX * ((float)px % targetWidth), incY * (float)Mathf.Floor(px / targetWidth)); + + result.SetPixels(scaledPixels, 0); + result.Apply(); + return result; + } + + public static void TextureEditorFloatParameter(string parameterName, ref float parameter, float rangeMin = -100f, float rangeMax = 100f, float resetValue = 0f) + { + EditorGUILayout.BeginHorizontal(); + { + parameter = EditorGUILayout.Slider(parameterName, parameter, rangeMin, rangeMax, GUILayout.MaxWidth(400)); + GUIContent resetButtonLabel = new GUIContent + { + text = "R", + tooltip = "Resets to default value" + }; + if (GUILayout.Button(resetButtonLabel, GUILayout.Width(20))) parameter = resetValue; + } + EditorGUILayout.EndHorizontal(); + } + + public static void TextureEditorColorParameter(string parameterName, ref Color parameter, Color resetValue) + { + EditorGUILayout.BeginHorizontal(); + { + GUIContent colorLabel = new GUIContent + { + text = parameterName, + tooltip = parameterName + }; + parameter = EditorGUILayout.ColorField(colorLabel, parameter, true, true, true, GUILayout.MaxWidth(400)); + GUIContent resetButtonLabel = new GUIContent + { + text = "R", + tooltip = "Resets to default value" + }; + if (GUILayout.Button(resetButtonLabel, GUILayout.Width(20))) parameter = resetValue; + } + EditorGUILayout.EndHorizontal(); + } + + public static void TextureEditorIntParameter(string parameterName, ref int parameter, int rangeMin = -100, int rangeMax = 100, int resetValue = 0) + { + EditorGUILayout.BeginHorizontal(); + { + parameter = EditorGUILayout.IntSlider(parameterName, parameter, rangeMin, rangeMax, GUILayout.MaxWidth(400)); + GUIContent resetButtonLabel = new GUIContent + { + text = "R", + tooltip = "Resets to default value" + }; + if (GUILayout.Button(resetButtonLabel, GUILayout.Width(20))) parameter = resetValue; + } + EditorGUILayout.EndHorizontal(); + } + + public static Shader FindShader(string shaderName) + { + string[] guids = AssetDatabase.FindAssets($"{shaderName} t:shader"); + foreach (string guid in guids) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + Shader shader = AssetDatabase.LoadAssetAtPath(path); + if (shader != null) + { + string fullShaderName = shader.name; + string actualShaderName = fullShaderName.Substring(fullShaderName.LastIndexOf('/') + 1); + if (actualShaderName == shaderName) return shader; + } + } + return null; + } + + public static void SetDirtyCurrentScene() + { + if (!Application.isPlaying) + { + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + } + + public static bool IsProjectAsset(Object objectToCheck) + { + bool res = false; + + if(objectToCheck != null) + { + res = AssetDatabase.Contains(objectToCheck); + } + return res; + } + + public static int GetNumLines(string input) + { + int res = input.Split("\n").Length; + return res; + } + + public static bool IsAllIn13DShader(string shaderName) + { + bool res = false; + + for (int i = 0; i < Constants.SHADERS_NAMES.Length; i++) + { + res = res || shaderName.Contains(Constants.SHADERS_NAMES[i]); + } + + return res; + } + + public static bool IsAllIn13DShader(Shader shader) + { + return IsAllIn13DShader(shader.name); + } + + public static Color GetRandomColor() + { + Color res = new Color(Random.value, Random.value, Random.value, 1.0f); + return res; + } + + public static void DrawButtonLink(string url) + { + if (EditorGUILayout.LinkButton(url)) + { + Application.OpenURL(url); + } + } + + public static bool ConstainsFileName(string[] pathArray, string fileName) + { + bool res = false; + + for(int i = 0; i < pathArray.Length; i++) + { + if (pathArray[i].EndsWith(fileName)) + { + res = true; + break; + } + } + + return res; + } + + public static bool ContainsAnyFolowingFileNames(string[] pathArray, string[] fileNames, string extension) + { + bool res = false; + + for(int i = 0; i < pathArray.Length; i++) + { + for(int j = 0; j < fileNames.Length; j++) + { + string fileName = $"{fileNames[j]}.{extension}"; + + if (pathArray[i].EndsWith(fileName)) + { + res = true; + break; + } + } + + if (res) + { + break; + } + } + + return res; + } + + public static AllIn1ShaderPropertyType GetShaderTypeByMaterialProperty(MaterialProperty matProperty) + { + AllIn1ShaderPropertyType res; + +#if UNITY_6000_2_OR_NEWER + switch (matProperty.propertyType) + { + case UnityEngine.Rendering.ShaderPropertyType.Color: + res = AllIn1ShaderPropertyType.Color; + break; + case UnityEngine.Rendering.ShaderPropertyType.Float: + res = AllIn1ShaderPropertyType.Float; + break; + case UnityEngine.Rendering.ShaderPropertyType.Int: + res = AllIn1ShaderPropertyType.Int; + break; + case UnityEngine.Rendering.ShaderPropertyType.Range: + res = AllIn1ShaderPropertyType.Range; + break; + case UnityEngine.Rendering.ShaderPropertyType.Texture: + res = AllIn1ShaderPropertyType.Texture; + break; + case UnityEngine.Rendering.ShaderPropertyType.Vector: + res = AllIn1ShaderPropertyType.Vector; + break; + default: + res = AllIn1ShaderPropertyType.Vector; + break; + } +#else + switch (matProperty.type) + { + case MaterialProperty.PropType.Color: + res = AllIn1ShaderPropertyType.Color; + break; + case MaterialProperty.PropType.Float: + res = AllIn1ShaderPropertyType.Float; + break; + case MaterialProperty.PropType.Int: + res = AllIn1ShaderPropertyType.Int; + break; + case MaterialProperty.PropType.Range: + res = AllIn1ShaderPropertyType.Range; + break; + case MaterialProperty.PropType.Texture: + res = AllIn1ShaderPropertyType.Texture; + break; + case MaterialProperty.PropType.Vector: + res = AllIn1ShaderPropertyType.Vector; + break; + default: + res = AllIn1ShaderPropertyType.Vector; + break; + } +#endif + return res; + + } + + public static string ReadFileTextWithTabs(string path, int numTabs) + { + string res = string.Empty; + + string[] allLines = File.ReadAllLines(path); + + for (int i = 0; i < allLines.Length; i++) + { + string line = allLines[i]; + for (int j = 0; j < numTabs; j++) + { + line = "\t" + line; + } + line += "\n"; + + res += line; + } + + return res; + } + + public static string UnifyEOL(string target) + { + string res = target; + + res = res.Replace("\r\n", "\n"); + res = res.Replace("\r", "\n"); + + return res; + } + } +} diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/EditorUtils.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Utilities/EditorUtils.cs.meta new file mode 100644 index 0000000..ca37de2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/EditorUtils.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 70da5d91445c6164eb028b7ce14af0f5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Utilities/EditorUtils.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/MaterialUtils.cs b/Assets/Plugins/AllIn13DShader/Editor/Utilities/MaterialUtils.cs new file mode 100644 index 0000000..ddd20a8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/MaterialUtils.cs @@ -0,0 +1,74 @@ +using System.Linq; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public static class MaterialUtils + { + public const string STR_OUTLINE_TYPE_NONE = "_OUTLINETYPE_NONE"; + public const string STR_CAST_SHADOWS_ON = "_CAST_SHADOWS_ON"; + public const string STR_RECEIVE_SHADOWS_ON = "_RECEIVE_SHADOWS_ON"; + + public static bool CheckMaterialShader(Material targetMat) + { + bool isOutline = !targetMat.shaderKeywords.Contains(STR_OUTLINE_TYPE_NONE); + bool shadowCasterPassEnabled = targetMat.shaderKeywords.Contains(STR_CAST_SHADOWS_ON) || targetMat.shaderKeywords.Contains(STR_RECEIVE_SHADOWS_ON); + +#if ALLIN13DSHADER_BIRP + shadowCasterPassEnabled = true; +#endif + + + bool shaderChanged = false; + + Shader oldShader = null; + Shader newShader = null; + Shader shaderToCompare = null; + + if (isOutline) + { + + if (shadowCasterPassEnabled) + { + shaderToCompare = GlobalConfiguration.instance.shOutline; + } + else + { + shaderToCompare = GlobalConfiguration.instance.shOutlineNoShadowCaster; + } + } + else + { + if (shadowCasterPassEnabled) + { + shaderToCompare = GlobalConfiguration.instance.shStandard; + } + else + { + shaderToCompare = GlobalConfiguration.instance.shStandardNoShadowCaster; + } + } + + if (targetMat.shader != shaderToCompare) + { + oldShader = targetMat.shader; + newShader = shaderToCompare; + + shaderChanged = true; + } + + if (shaderChanged) + { + targetMat.shader = newShader; + + if (AssetDatabase.IsMainAsset(targetMat)) + { + EditorUtility.SetDirty(targetMat); + } + } + + return shaderChanged; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/MaterialUtils.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Utilities/MaterialUtils.cs.meta new file mode 100644 index 0000000..892decb --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/MaterialUtils.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 76cb362c3af9e6f418634ca3a9510c9c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Utilities/MaterialUtils.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineChecker.cs b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineChecker.cs new file mode 100644 index 0000000..93392f1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineChecker.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using UnityEditor; +using UnityEditor.Build; + +#if UNITY_2019_3_OR_NEWER + +namespace AllIn13DShader +{ + public class RenderPipelineChecker + { + private const string SYMBOL_URP = "ALLIN13DSHADER_URP"; + private const string SYMBOL_HDRP = "ALLIN13DSHADER_HDRP"; + private const string SYMBOL_BIRP = "ALLIN13DSHADER_BIRP"; + + private const string HDRP_PACKAGE = "HDRenderPipelineAsset"; + private const string URP_PACKAGE = "UniversalRenderPipelineAsset"; + + public static bool IsHDRP + { + get; private set; + } + public static bool IsURP + { + get; private set; + } + public static bool IsStandardRP + { + get; private set; + } + + public static RenderPipelineEnum CurrentRenderPipeline + { + get; private set; + } + + public static void RefreshData() + { + IsHDRP = DoesTypeExist(HDRP_PACKAGE); + IsURP = DoesTypeExist(URP_PACKAGE); + + if (!(IsHDRP || IsURP)) + { + IsStandardRP = true; + } + + else if (IsURP) + { + CurrentRenderPipeline = RenderPipelineEnum.URP; + } + else if (IsHDRP) + { + CurrentRenderPipeline = RenderPipelineEnum.HDRP; + } + else + { + CurrentRenderPipeline = RenderPipelineEnum.BIRP; + } + } + + public static bool DoesTypeExist(string className) + { + var foundType = (from assembly in AppDomain.CurrentDomain.GetAssemblies() + from type in GetTypesSafe(assembly) + where type.Name == className + select type).FirstOrDefault(); + + return foundType != null; + } + + public static IEnumerable GetTypesSafe(System.Reflection.Assembly assembly) + { + Type[] types; + + try + { + types = assembly.GetTypes(); + } + catch (ReflectionTypeLoadException e) + { + types = e.Types; + } + + return types.Where(x => x != null); + } + + public static bool IsRenderPipelineDefined() + { + bool res = false; + + BuildTarget buildTarget = EditorUserBuildSettings.activeBuildTarget; + BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; + + NamedBuildTarget namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup); + string[] defineSymbols = new string[0]; + PlayerSettings.GetScriptingDefineSymbols(namedBuildTarget, out defineSymbols); + + for (int i = defineSymbols.Length - 1; i >= 0; i--) + { + if (defineSymbols[i] == SYMBOL_URP || defineSymbols[i] == SYMBOL_HDRP || defineSymbols[i] == SYMBOL_BIRP) + { + res = true; + } + } + + return res; + } + + private static string[] GetSymbolsWithoutPipeline() + { + BuildTarget buildTarget = EditorUserBuildSettings.activeBuildTarget; + BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; + + NamedBuildTarget namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup); + string[] defineSymbols = new string[0]; + PlayerSettings.GetScriptingDefineSymbols(namedBuildTarget, out defineSymbols); + + for (int i = defineSymbols.Length - 1; i >= 0; i--) + { + if (defineSymbols[i] == SYMBOL_URP || defineSymbols[i] == SYMBOL_HDRP || defineSymbols[i] == SYMBOL_BIRP) + { + ArrayUtility.RemoveAt(ref defineSymbols, i); + } + } + + return defineSymbols; + } + + public static void RemovePipelineSymbols() + { + string[] defineSymbols = GetSymbolsWithoutPipeline(); + ApplyDefineSymbols(defineSymbols); + } + + private static void ApplyDefineSymbols(string[] defineSymbols) + { + BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; + NamedBuildTarget namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup); + + PlayerSettings.SetScriptingDefineSymbols(namedBuildTarget, defineSymbols); + } + + public static void CheckRenderPipeline() + { + RefreshData(); + + RenderPipelineEnum lastRenderPipeline = (RenderPipelineEnum)SessionState.GetInt(Constants.LAST_RENDER_PIPELINE_CHECKED_KEY, 0); + + if (lastRenderPipeline != CurrentRenderPipeline || !IsRenderPipelineDefined()) + { + string[] defineSymbols = GetSymbolsWithoutPipeline(); + if (IsURP) + { + ArrayUtility.Add(ref defineSymbols, SYMBOL_URP); + } + else if (IsHDRP) + { + ArrayUtility.Add(ref defineSymbols, SYMBOL_HDRP); + } + else + { + ArrayUtility.Add(ref defineSymbols, SYMBOL_BIRP); + } + + ApplyDefineSymbols(defineSymbols); + SessionState.SetInt(Constants.LAST_RENDER_PIPELINE_CHECKED_KEY, (int)CurrentRenderPipeline); + } + } + + [InitializeOnLoadMethod] + public static void ScriptsReloaded() + { + CheckRenderPipeline(); + } + } +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineChecker.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineChecker.cs.meta new file mode 100644 index 0000000..762ccaa --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineChecker.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 5d4b26b0600ea8841a3d0638622becb6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineChecker.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineEnum.cs b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineEnum.cs new file mode 100644 index 0000000..646d6f8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineEnum.cs @@ -0,0 +1,10 @@ +namespace AllIn13DShader +{ + public enum RenderPipelineEnum + { + NONE = 0, + BIRP = 1, + URP = 2, + HDRP = 3 + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineEnum.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineEnum.cs.meta new file mode 100644 index 0000000..361ec3f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineEnum.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 3d4a196d595a82a44b10716a524759be +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Utilities/RenderPipelineEnum.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/RightClickMaterialCreator.cs b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RightClickMaterialCreator.cs new file mode 100644 index 0000000..a8446e3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RightClickMaterialCreator.cs @@ -0,0 +1,73 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public static class RightClickMaterialCreator + { + private const string MENU_PATH = "Assets/Create/AllIn13DShader/Materials"; + + public static void CreateMaterial(Material matSource) + { + string saveFolderPath = AssetDatabase.GetAssetPath(Selection.activeObject); + + if (!AssetDatabase.IsValidFolder(saveFolderPath)) + { + saveFolderPath = GlobalConfiguration.instance.MaterialSavePath; + } + + Material mat = new Material(matSource); + + string materialPath = Path.Combine(saveFolderPath, AllIn13DShaderConfig.MATERIAL_NAME_DEFAULT); + materialPath = AssetDatabase.GenerateUniqueAssetPath(materialPath); + AssetDatabase.CreateAsset(mat, materialPath); + + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + + Selection.activeObject = mat; + } + + private static GlobalConfiguration GetGlobalConfiguration() + { + GlobalConfiguration res = EditorUtils.FindAsset("GlobalConfiguration"); + return res; + } + + [MenuItem(MENU_PATH + "/Default Material", false, 1)] + public static void CreateMaterialDefault() + { + GlobalConfiguration globalConfiguration = GetGlobalConfiguration(); + CreateMaterial(globalConfiguration.defaultPreset); + } + + [MenuItem(MENU_PATH + "/Toon Material", false, 1)] + public static void CreateMaterialToon() + { + GlobalConfiguration globalConfiguration = GetGlobalConfiguration(); + CreateMaterial(globalConfiguration.toonMaterial); + } + + [MenuItem(MENU_PATH + "/PBR Material", false, 1)] + public static void CreateMaterialPBR() + { + GlobalConfiguration globalConfiguration = GetGlobalConfiguration(); + CreateMaterial(globalConfiguration.standardPBRMaterial); + } + + [MenuItem(MENU_PATH + "/Basic Lighting Material", false, 1)] + public static void CreateMaterialBasic() + { + GlobalConfiguration globalConfiguration = GetGlobalConfiguration(); + CreateMaterial(globalConfiguration.standardBasicMaterial); + } + + [MenuItem(MENU_PATH + "/AllIn13D Look", false, 1)] + public static void CreateMaterialAllIn3DLook() + { + GlobalConfiguration globalConfiguration = GetGlobalConfiguration(); + CreateMaterial(globalConfiguration.allIn13dDShaderLookMaterial); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Utilities/RightClickMaterialCreator.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RightClickMaterialCreator.cs.meta new file mode 100644 index 0000000..1a85bce --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Utilities/RightClickMaterialCreator.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: adcc78e01c8d09c46b440d328c933fc8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Utilities/RightClickMaterialCreator.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows.meta new file mode 100644 index 0000000..06a9fb7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 64e05ee698fb191438d71e3dd3bef7a5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/AllIn13DShaderWindow.cs b/Assets/Plugins/AllIn13DShader/Editor/Windows/AllIn13DShaderWindow.cs new file mode 100644 index 0000000..1894664 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/AllIn13DShaderWindow.cs @@ -0,0 +1,246 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class AllIn13DShaderWindow : EditorWindow + { + private static AllIn13DShaderWindow instance; + + private Vector2 scrollPosition; + + private AssetWindowTabDrawer currentTabDrawer; + + private int currTab = 0; + private string[] tabsNames; + private AssetWindowTabDrawer[] tabDrawers; + + private CommonStyles commonStyles; + private GlobalConfiguration globalConfiguration; + + private Texture imageInspector; + + private SavePathsTabDrawer savePathsTabDrawer; + private TextureEditorTabDrawer textureEditorTabDrawer; + private TextureCreatorTabDrawer textureCreatorTabDrawer; + + private OverrideMaterialsTabDrawer overrideMaterialsTabDrawer; + private OtherTabDrawer otherTabDrawer; + private EffectsProfileTabDrawer effectsProfileTabDrawer; + private URPSettingsDrawer urpSettingsDrawer; + + + private bool initialized; + + + [MenuItem("Tools/AllIn1/3DShaderWindow")] + public static void ShowAllIn13DShaderWindow() + { + if(instance == null) + { + instance = GetWindow("All In 1 3DShader Window"); + } + } + + private void Init() + { + commonStyles = new CommonStyles(); + globalConfiguration = EditorUtils.FindAssetByName("GlobalConfiguration"); + + PropertiesConfigCollection propertiesConfigCollection = EditorUtils.FindAsset("PropertiesConfigCollection") as PropertiesConfigCollection; + + scrollPosition = Vector2.zero; + + savePathsTabDrawer = new SavePathsTabDrawer(commonStyles, this); + textureEditorTabDrawer = new TextureEditorTabDrawer(commonStyles, this); + textureCreatorTabDrawer = new TextureCreatorTabDrawer(commonStyles, this); + overrideMaterialsTabDrawer = new OverrideMaterialsTabDrawer(commonStyles, this); + otherTabDrawer = new OtherTabDrawer(globalConfiguration, commonStyles, this); + effectsProfileTabDrawer = new EffectsProfileTabDrawer(propertiesConfigCollection.propertiesConfig, globalConfiguration, commonStyles, this); + urpSettingsDrawer = new URPSettingsDrawer(commonStyles, this); + +#if ALLIN13DSHADER_URP + tabDrawers = new AssetWindowTabDrawer[] + { + savePathsTabDrawer, + textureEditorTabDrawer, + textureCreatorTabDrawer, + overrideMaterialsTabDrawer, + effectsProfileTabDrawer, + urpSettingsDrawer, + otherTabDrawer + }; + +#else + tabDrawers = new AssetWindowTabDrawer[] + { + savePathsTabDrawer, + textureEditorTabDrawer, + textureCreatorTabDrawer, + overrideMaterialsTabDrawer, + effectsProfileTabDrawer, + otherTabDrawer + }; +#endif + + tabsNames = new string[tabDrawers.Length]; + for(int i = 0; i < tabsNames.Length; i++) + { + tabsNames[i] = tabDrawers[i].GetTabName(); + } + + if (imageInspector == null) + { + imageInspector = AllIn13DShaderConfig.GetInspectorImage(); + } + + + + currentTabDrawer = savePathsTabDrawer; + + initialized = true; + } + + private void OnEnable() + { + Init(); + + EditorApplication.playModeStateChanged += PlayModeStateChanged; + currentTabDrawer.OnEnable(); + } + + private void OnDisable() + { + EditorApplication.playModeStateChanged -= PlayModeStateChanged; + currentTabDrawer.OnDisable(); + } + + private void OnDestroy() + { + WindowClosed(); + } + + private void WindowClosed() + { + overrideMaterialsTabDrawer.Close(); + Repaint(); + } + + private void OnGUI() + { + if (!initialized) + { + Init(); + } + + commonStyles.InitStyles(); + +#if ALLIN13DSHADER_URP + bool urpCorrectlyConfigured = URPConfigurator.IsURPCorrectlyConfigured(); + if (!urpCorrectlyConfigured) + { + Draw_URPError(); + } + else + { + Draw(); + } +#else + Draw(); +#endif + + } + + private void Draw() + { + DrawEditor(); + } + + private void DrawEditor() + { + using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPosition, GUILayout.Width(position.width), GUILayout.Height(position.height))) + { + scrollPosition = scrollView.scrollPosition; + + if (imageInspector) + { + Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(50)); + GUI.DrawTexture(rect, imageInspector, ScaleMode.ScaleToFit, true); + } + + EditorUtils.DrawThinLine(); + + if (Application.isPlaying) + { + DrawPlayMode(); + } + else + { + int newTab = GUILayout.Toolbar(currTab, tabsNames); + AssetWindowTabDrawer newTabDrawer = tabDrawers[newTab]; + + if (newTabDrawer != currentTabDrawer) + { + currentTabDrawer.Hide(); + newTabDrawer.Show(); + + this.currTab = newTab; + this.currentTabDrawer = newTabDrawer; + } + + EditorUtils.DrawThinLine(); + currentTabDrawer.Draw(); + } + + GUILayout.Space(10); + EditorUtils.DrawThinLine(); + GUILayout.Label("Current asset version is " + Constants.VERSION, EditorStyles.boldLabel); + } + } + + private void DrawPlayMode() + { + GUILayout.Label("Not available during play mode", commonStyles.bigLabel); + } + + private void Draw_URPError() + { + EditorGUILayout.LabelField(CommonMessages.URP_PIPELINE_NOT_ASSIGNED, commonStyles.warningLabel); + EditorUtils.DrawButtonLink(CommonMessages.URP_PIPELINE_NOT_ASSIGNED_DOC_LINK); + } + + private void PlayModeStateChanged(PlayModeStateChange state) + { + if(state == PlayModeStateChange.ExitingEditMode) + { + currentTabDrawer.ExitingEditMode(); + } + else if(state == PlayModeStateChange.EnteredPlayMode) + { + currentTabDrawer.EnteredPlayMode(); + Repaint(); + } + else if(state == PlayModeStateChange.ExitingPlayMode) + { + Init(); + Repaint(); + } + } + + public static void AllAssetProcessed() + { + CheckURPCorrectlyConfigured(); + } + + private static void CheckURPCorrectlyConfigured() + { +#if ALLIN13DSHADER_URP + if (!URPConfigurator.IsURPCorrectlyConfigured()) + { + ShowAllIn13DShaderWindow(); + } +#endif + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/AllIn13DShaderWindow.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows/AllIn13DShaderWindow.cs.meta new file mode 100644 index 0000000..7b33c56 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/AllIn13DShaderWindow.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 51e8848e3c58c334eacf2c12d0e69b68 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Windows/AllIn13DShaderWindow.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/AssetWindowTabDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Windows/AssetWindowTabDrawer.cs new file mode 100644 index 0000000..0a600df --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/AssetWindowTabDrawer.cs @@ -0,0 +1,33 @@ +namespace AllIn13DShader +{ + public abstract class AssetWindowTabDrawer + { + protected CommonStyles commonStyles; + protected AllIn13DShaderWindow parentWindow; + + public AssetWindowTabDrawer(CommonStyles commonStyles, AllIn13DShaderWindow parentWindow) + { + this.commonStyles = commonStyles; + this.parentWindow = parentWindow; + } + + public abstract void Hide(); + + public abstract void Show(); + + public abstract void OnDisable(); + + public abstract void OnEnable(); + + public abstract void Draw(); + + public abstract void EnteredPlayMode(); + + public virtual void ExitingEditMode() + { + + } + + public abstract string GetTabName(); + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/AssetWindowTabDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows/AssetWindowTabDrawer.cs.meta new file mode 100644 index 0000000..31209bb --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/AssetWindowTabDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 00d52e9709d8b1b439bae51fe4b61969 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Windows/AssetWindowTabDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/EffectsProfileTabDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Windows/EffectsProfileTabDrawer.cs new file mode 100644 index 0000000..e924be5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/EffectsProfileTabDrawer.cs @@ -0,0 +1,151 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class EffectsProfileTabDrawer : AssetWindowTabDrawer + { + private const string TAB_NAME = "Active Effects List"; + + private EffectsProfileCollection effectsProfileCollection; + private EffectsProfile effectsProfile; + private PropertiesConfig propertiesConfig; + + public EffectsProfileTabDrawer(PropertiesConfig propertiesConfig, GlobalConfiguration globalConfiguration, CommonStyles commonStyles, AllIn13DShaderWindow parentWindow) : base(commonStyles, parentWindow) + { + this.propertiesConfig = propertiesConfig; + this.effectsProfileCollection = globalConfiguration.effectsProfileCollection; + this.effectsProfile = effectsProfileCollection.generalProfile; + } + + public override void Draw() + { + EditorGUILayout.BeginHorizontal(); + if(GUILayout.Button("Enable All")) + { + EnableAll(); + } + + if(GUILayout.Button("Disable All")) + { + DisableAll(); + } + EditorGUILayout.EndHorizontal(); + + EditorGUI.BeginChangeCheck(); + for(int i = 0; i < effectsProfile.groups.Count; i++) + { + DrawGroup(effectsProfile.groups[i]); + } + bool hasChanges = EditorGUI.EndChangeCheck(); + if (hasChanges) + { + EditorUtility.SetDirty(effectsProfileCollection); + } + + if (GUILayout.Button("Configure")) + { + Configure(); + } + } + + public override void EnteredPlayMode() + { + + } + + public override void Hide() + { + + } + + public override void OnDisable() + { + + } + + public override void OnEnable() + { + + } + + public override void Show() + { + + } + + private void Configure() + { + ShaderFeaturesFileCreator.CreateFile(effectsProfile); + } + + private void DrawGroup(EffectsProfileGroup effectsProfileGroup) + { + EditorGUILayout.BeginVertical(); + GUILayout.Label(effectsProfileGroup.effectGroupConfig.displayName, commonStyles.bigLabel); + + for(int i = 0; i < effectsProfileGroup.entries.Count; i++) + { + DrawEntry(effectsProfileGroup.entries[i]); + } + + GUILayout.Space(15f); + + EditorGUILayout.EndVertical(); + } + + private void DrawEntry(EffectsProfileEntry entry) + { + string label = $"{entry.GetDisplayIndex()}. {entry.displayName}"; + + AllIn13DEffectConfig effectConfig = propertiesConfig.FindEffectConfigByID(entry.effectID); + entry.BindEffectConfig(effectConfig); + + EditorGUILayout.BeginVertical(); + + EditorGUILayout.BeginHorizontal(); + entry.isEnabled = GUILayout.Toggle(entry.isEnabled, string.Empty, GUILayout.Width(15)); + GUILayout.Label(label, GUILayout.Width(200f)); + + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.EndVertical(); + } + + private void DrawSubKeywordToggle(SubkeywordEntryToggle subkeywordEntryToggle) + { + EditorGUILayout.BeginHorizontal(commonStyles.shaderPropertiesStyle); + + subkeywordEntryToggle.isEnabled = GUILayout.Toggle(subkeywordEntryToggle.isEnabled, string.Empty, GUILayout.Width(15)); + GUILayout.Label(subkeywordEntryToggle.displayName, GUILayout.Width(200f)); + + EditorGUILayout.EndHorizontal(); + } + + private void DrawSubKeywordEnum(SubkeywordEntryEnum subkeywordEntryEnum) + { + EditorGUILayout.BeginHorizontal(commonStyles.shaderPropertiesStyle); + + subkeywordEntryEnum.kwIndexEnabled = EditorGUILayout.Popup(subkeywordEntryEnum.kwIndexEnabled, subkeywordEntryEnum.displayNames); + + EditorGUILayout.EndHorizontal(); + } + + private void EnableAll() + { + effectsProfile.EnableAllEffects(); + EditorUtility.SetDirty(effectsProfileCollection); + } + + private void DisableAll() + { + effectsProfile.DisableAllEffects(); + EditorUtility.SetDirty(effectsProfileCollection); + } + + public override string GetTabName() + { + return TAB_NAME; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/EffectsProfileTabDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows/EffectsProfileTabDrawer.cs.meta new file mode 100644 index 0000000..bcb042c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/EffectsProfileTabDrawer.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: fc7d46d942abc6d4693c2383e2ae5fe2 +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Windows/EffectsProfileTabDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/OtherTabDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Windows/OtherTabDrawer.cs new file mode 100644 index 0000000..961045f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/OtherTabDrawer.cs @@ -0,0 +1,101 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class OtherTabDrawer : AssetWindowTabDrawer + { + private const string TAB_NAME = "Other"; + + private GlobalConfiguration globalConfiguration; + + public OtherTabDrawer(GlobalConfiguration globalConfiguration, CommonStyles commonStyles, AllIn13DShaderWindow parentWindow) : base(commonStyles, parentWindow) + { + this.globalConfiguration = globalConfiguration; + + if (globalConfiguration.defaultPreset == null) + { + globalConfiguration.projectType = GlobalConfiguration.ProjectType.STANDARD_BASIC; + globalConfiguration.RefreshDefaultMaterial(); + globalConfiguration.Save(); + } + } + + public override void Show() + { + + } + + public override void Hide() + { + + } + + public override void OnEnable() + { + + } + + public override void OnDisable() + { + + } + + public override void EnteredPlayMode() + { + + } + + public override void Draw() + { + GUILayout.Label("Default Materials", commonStyles.bigLabel); + GUILayout.Space(20); + + EditorGUI.BeginChangeCheck(); + globalConfiguration.projectType = (GlobalConfiguration.ProjectType)EditorGUILayout.EnumPopup("Project Type", globalConfiguration.projectType); + bool projectTypeChanged = EditorGUI.EndChangeCheck(); + + bool disabled = globalConfiguration.projectType != GlobalConfiguration.ProjectType.CUSTOM; + EditorGUI.BeginDisabledGroup(disabled); + EditorGUI.BeginChangeCheck(); + globalConfiguration.defaultPreset = (Material)EditorGUILayout.ObjectField("Default Material", globalConfiguration.defaultPreset, typeof(Material), false); + bool defaultPresetChanged = EditorGUI.EndChangeCheck(); + EditorGUI.EndDisabledGroup(); + + if (projectTypeChanged) + { + globalConfiguration.RefreshDefaultMaterial(); + } + + if(projectTypeChanged || defaultPresetChanged) + { + globalConfiguration.Save(); + } + + + EditorGUILayout.Space(); + EditorUtils.DrawThinLine(); + EditorGUILayout.Space(); + + EditorGUILayout.Space(); + if (GUILayout.Button("Refresh the Material Inspector Properties Configuration")) + { + ShadersCreatorTool.BuildShaderFiles(); + PropertiesConfigCollection propertiesConfigCollection = PropertiesConfigCreator.CreateConfig(); + + EffectsProfileCollection effectsProfileCollection = EffectsProfileCollection.CreateAsset(propertiesConfigCollection); + if (AssetDatabase.IsValidFolder(Constants.DEMO_SHADERS_BAKED_FOLDER_PATH)) + { + effectsProfileCollection.CheckBakedShadersFolder(Constants.DEMO_SHADERS_BAKED_FOLDER_PATH, propertiesConfigCollection.propertiesConfig); + } + } + + EditorGUILayout.LabelField("The asset uses auto generated cached data to display the properties of the Material inspector\nYou should never need this button", commonStyles.wordWrappedStyle); + } + + public override string GetTabName() + { + return TAB_NAME; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/OtherTabDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows/OtherTabDrawer.cs.meta new file mode 100644 index 0000000..4d5c983 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/OtherTabDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 305faffa5984380458d6390103d1a838 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Windows/OtherTabDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/OverrideMaterialsTabDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Windows/OverrideMaterialsTabDrawer.cs new file mode 100644 index 0000000..8f41354 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/OverrideMaterialsTabDrawer.cs @@ -0,0 +1,489 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; +using UnityEngine.Rendering; +using UnityEngine.SceneManagement; + +namespace AllIn13DShader +{ + public class OverrideMaterialsTabDrawer : AssetWindowTabDrawer + { + private const string TAB_NAME = "Override Materials"; + + private enum State + { + NONE = 0, + PREVIEW = 1, + } + + private PropertySelectorAuxWindow propertySelectorWindow; + + private State state; + + private static MaterialOverrideData overrideData; + private SerializedObject dataSO; + private SerializedProperty spFolders; + + private GUIStyle propertiesStyle; + + public OverrideMaterialsTabDrawer(CommonStyles commonStyles, AllIn13DShaderWindow parentWindow) : base(commonStyles, parentWindow) + { + Initialize(); + } + + private void Initialize() + { + overrideData = ScriptableObject.CreateInstance(); + overrideData.Initialize(); + + state = State.NONE; + + dataSO = new SerializedObject(overrideData); + spFolders = dataSO.FindProperty("folders"); + } + + private void SubscribeEvents() + { + EditorApplication.wantsToQuit += OnWantsToQuit; + EditorSceneManager.sceneClosing += OnSceneClosing; + EditorSceneManager.sceneSaving += OnSceneSaving; + EditorSceneManager.sceneSaved += OnSceneSaved; + EditorSceneManager.sceneDirtied += OnSceneDirtied; + + EditorApplication.hierarchyChanged += OnHierarchyChanged; + + AssemblyReloadEvents.beforeAssemblyReload += BeforeAssemblyReload; + + } + + private void UnsubscribeEvents() + { + EditorApplication.wantsToQuit -= OnWantsToQuit; + EditorSceneManager.sceneClosing -= OnSceneClosing; + EditorSceneManager.sceneSaving -= OnSceneSaving; + EditorSceneManager.sceneSaved -= OnSceneSaved; + EditorSceneManager.sceneDirtied -= OnSceneDirtied; + + EditorApplication.hierarchyChanged -= OnHierarchyChanged; + + AssemblyReloadEvents.beforeAssemblyReload -= BeforeAssemblyReload; + } + + public override void OnEnable() + { + SubscribeEvents(); + } + + public override void OnDisable() + { + UnsubscribeEvents(); + } + + public override void Show() + { + Initialize(); + SubscribeEvents(); + } + + public override void Hide() + { + UnsubscribeEvents(); + Close(); + } + + //public void Setup(CommonStyles commonStyles, AllIn13DShaderWindow parentWindow) + //{ + // this.commonStyles = commonStyles; + // this.parentWindow = parentWindow; + //} + + public override void EnteredPlayMode() + { + + } + + public override void ExitingEditMode() + { + EndOverrideProcess(false); + + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + AssetDatabase.SaveAssets(); + + UnsubscribeEvents(); + } + + public override void Draw() + { + if(propertiesStyle == null) + { + propertiesStyle = new GUIStyle(EditorStyles.helpBox); + propertiesStyle.margin = new RectOffset(0, 0, 0, 0); + } + + dataSO.Update(); + + GUILayout.Space(10f); + + if (state == State.NONE) + { + DrawStateNone(); + } + else + { + DrawStatePreview(); + } + + dataSO.ApplyModifiedProperties(); + } + + private void StartOverrideProcess() + { + overrideData.ResetData(); + overrideData.CreateRendererOverride(); + + overrideData.ShowPreviewChanges(); + + state = State.PREVIEW; + } + + private void EndOverrideProcess(bool applyChanges) + { + if (applyChanges) + { + List affectedMaterials = overrideData.CollectAffectedMaterials(); + + string title = "Overriding AllIn13D materials"; + string message = $"You are about to override {affectedMaterials.Count} materials"; + string okButton = "Override"; + string cancelButton = "Cancel"; + + bool isOk = EditorUtility.DisplayDialog(title, message, okButton, cancelButton); + + if (isOk) + { + overrideData.ApplyChangesToMaterials(affectedMaterials); + overrideData.EndOverrideProcess(); + + if(overrideData.applyTarget == MaterialOverrideData.ApplyTarget.CURRENT_SCENE) + { + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + AssetDatabase.SaveAssets(); + } + + state = State.NONE; + } + } + else + { + overrideData.EndOverrideProcess(); + state = State.NONE; + } + } + + private void DrawStateNone() + { + if (GUILayout.Button("Start")) + { + StartOverrideProcess(); + } + } + + private void DrawStatePreview() + { + overrideData.applyTarget = (MaterialOverrideData.ApplyTarget)EditorGUILayout.EnumPopup("Apply Target", overrideData.applyTarget); + if(overrideData.applyTarget == MaterialOverrideData.ApplyTarget.SELECTED_FOLDERS) + { + EditorGUILayout.PropertyField(spFolders); + } + + GUILayout.Space(20f); + + if (GUILayout.Button("+")) + { + propertySelectorWindow = PropertySelectorAuxWindow.GetWindow(title: "Select Property", utility: true); + propertySelectorWindow.Setup(PropertyAddedCallback); + } + + GUILayout.Space(20f); + + EditorGUI.BeginChangeCheck(); + + for(int i = 0; i < overrideData.generalPropertiesOverrides.Count; i++) + { + DrawOverriddenEffectProperty(overrideData.generalPropertiesOverrides[i]); + } + + if (!overrideData.IsEmpty()) + { + GUILayout.Space(10f); + } + + for (int i = 0; i < overrideData.effectOverrides.Count; i++) + { + DrawEffectOverride(overrideData.effectOverrides[i]); + } + + if (EditorGUI.EndChangeCheck()) + { + overrideData.ShowPreviewChanges(); + } + + EditorGUILayout.BeginHorizontal(); + + EditorGUI.BeginDisabledGroup(!overrideData.IsApplyEnabled() || overrideData.IsEmpty()); + if (GUILayout.Button("Apply")) + { + EndOverrideProcess(applyChanges: true); + } + EditorGUI.EndDisabledGroup(); + + if (GUILayout.Button("Cancel")) + { + EndOverrideProcess(applyChanges: false); + } + + EditorGUILayout.EndHorizontal(); + } + + private void DrawEffectOverride(AbstractEffectOverride effectOverride) + { + EditorGUILayout.BeginHorizontal(); + + float lastLabelWidth = EditorGUIUtility.labelWidth; + EditorGUIUtility.labelWidth = 150f; + EditorGUI.BeginChangeCheck(); + effectOverride.overrideEnabled = EditorGUILayout.Toggle($"{effectOverride.displayName} Override", effectOverride.overrideEnabled); + if (EditorGUI.EndChangeCheck()) + { + overrideData.RebuildPreviewMaterial(); + } + EditorGUIUtility.labelWidth = lastLabelWidth; + + EditorGUI.BeginDisabledGroup(!effectOverride.overrideEnabled); + if (effectOverride is EffectToggleOverride) + { + EffectToggleOverride effectToggleOverride = (EffectToggleOverride)effectOverride; + effectToggleOverride.boolValue = EditorGUILayout.Toggle("On/Off", effectToggleOverride.boolValue); + } + else if(effectOverride is EffectEnumOverride) + { + EffectEnumOverride effectEnumOverride = (EffectEnumOverride)effectOverride; + effectEnumOverride.index = EditorGUILayout.Popup("Value", effectEnumOverride.index, effectEnumOverride.enumOptions); + } + EditorGUI.EndDisabledGroup(); + + if (GUILayout.Button("-", GUILayout.Width(50f))) + { + overrideData.RemoveEffectOverride(effectOverride); + } + + EditorGUILayout.EndHorizontal(); + + DrawEffectOverrideProperties(effectOverride); + } + + private void DrawEffectOverrideProperties(AbstractEffectOverride effectOverride) + { + EditorGUILayout.BeginVertical(propertiesStyle); + for (int i = 0; i < effectOverride.propertyOverrides.Count; i++) + { + DrawOverriddenEffectProperty(effectOverride.propertyOverrides[i]); + } + EditorGUILayout.EndVertical(); + } + + private void DrawOverriddenEffectProperty(PropertyOverride propertyOverride) + { + EditorGUILayout.BeginHorizontal(); + if (propertyOverride.propertyOverrideType == PropertyOverrideType.ENUM) + { + propertyOverride.floatValue = EditorGUILayout.Popup(propertyOverride.displayName, (int)propertyOverride.floatValue, propertyOverride.keywords); + } + else if (propertyOverride.propertyOverrideType == PropertyOverrideType.TOGGLE) + { + bool toggleBool = ((int)propertyOverride.floatValue) == 1f; + toggleBool = EditorGUILayout.Toggle(propertyOverride.displayName, toggleBool); + + float toggleFloat = toggleBool ? 1f : 0f; + propertyOverride.floatValue = toggleFloat; + } + else + { + switch (propertyOverride.shaderPropertyType) + { + case ShaderPropertyType.Float: + propertyOverride.floatValue = EditorGUILayout.FloatField(propertyOverride.displayName, propertyOverride.floatValue); + break; + case ShaderPropertyType.Range: + propertyOverride.floatValue = EditorGUILayout.Slider(propertyOverride.displayName, propertyOverride.floatValue, propertyOverride.rangeLimits.x, propertyOverride.rangeLimits.y); + break; + case ShaderPropertyType.Int: + propertyOverride.intValue = EditorGUILayout.IntField(propertyOverride.displayName, propertyOverride.intValue); + break; + case ShaderPropertyType.Color: + GUIContent guiContent = new GUIContent(propertyOverride.displayName); + propertyOverride.colorValue = EditorGUILayout.ColorField(guiContent, propertyOverride.colorValue, true, true, propertyOverride.isHDR); + break; + case ShaderPropertyType.Texture: + EditorGUILayout.BeginVertical(); + propertyOverride.texValue = (Texture)EditorGUILayout.ObjectField(propertyOverride.displayName, propertyOverride.texValue, typeof(Texture), false); + + float lastLabelWidth = EditorGUIUtility.labelWidth; + if (propertyOverride.hasTilingAndOffset) + { + EditorGUILayout.BeginHorizontal(); + Vector2 tiling = new Vector2(propertyOverride.tilingAndOffset.x, propertyOverride.tilingAndOffset.y); + EditorGUILayout.LabelField("Tiling", GUILayout.Width(50)); + tiling = EditorGUILayout.Vector2Field(string.Empty, tiling, GUILayout.Width(400)); + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + Vector2 offset = new Vector2(propertyOverride.tilingAndOffset.z, propertyOverride.tilingAndOffset.w); + EditorGUILayout.LabelField("Offset", GUILayout.Width(50)); + offset = EditorGUILayout.Vector2Field(string.Empty, offset, GUILayout.Width(400)); + EditorGUILayout.EndHorizontal(); + + propertyOverride.tilingAndOffset = new Vector4(tiling.x, tiling.y, offset.x, offset.y); + } + EditorGUIUtility.labelWidth = lastLabelWidth; + + + EditorGUILayout.EndVertical(); + break; + case ShaderPropertyType.Vector: + propertyOverride.vectorValue = EditorGUILayout.Vector4Field(propertyOverride.displayName, propertyOverride.vectorValue); + break; + } + } + + if (GUILayout.Button("-", GUILayout.Width(50f))) + { + overrideData.RemovePropertyOverride(propertyOverride); + overrideData.RebuildPreviewMaterial(); + } + + EditorGUILayout.EndHorizontal(); + } + + private void PropertyAddedCallback(AllIn13DEffectConfig effectConfig, int propertyIndex, Shader shader, + PropertySelectorAuxWindow.TypeOfPropertyAdded typeOfPropertyAdded) + { + if(typeOfPropertyAdded == PropertySelectorAuxWindow.TypeOfPropertyAdded.EFFECT_MAIN) + { + overrideData.AddCopmleteEffectOverride(effectConfig, shader); + } + else if(typeOfPropertyAdded == PropertySelectorAuxWindow.TypeOfPropertyAdded.GLOBAL_PROPERTY || typeOfPropertyAdded == PropertySelectorAuxWindow.TypeOfPropertyAdded.ADVANCED_PROPERTY) + { + overrideData.AddGeneralPropertyOverride(propertyIndex, shader); + } + //else if(typeOfPropertyAdded == PropertySelectorAuxWindow.TypeOfPropertyAdded.EFFECT_MAIN) + //{ + // overrideData.AddEffectOverride(effectConfig); + //} + + overrideData.ShowPreviewChanges(); + parentWindow.Repaint(); + } + + public void Close() + { + EndOverrideProcess(applyChanges: false); + //EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + //AssetDatabase.SaveAssets(); + + if (propertySelectorWindow != null) + { + propertySelectorWindow.Close(); + } + } + + private void OnSceneClosing(Scene scene, bool removingScene) + { + Close(); + + EditorSceneManager.MarkSceneDirty(scene); + AssetDatabase.SaveAssets(); + + Initialize(); + } + + private void OnSceneSaving(Scene scene, string path) + { + overrideData.UseMaterialSource(); + EditorSceneManager.MarkSceneDirty(scene); + } + + private void OnSceneSaved(Scene scene) + { + if(state == State.PREVIEW) + { + overrideData.UsePreviewMaterials(); + } + } + + private void OnSceneDirtied(Scene scene) + { + if(state == State.PREVIEW && Event.current != null) + { + bool deletingObject = false; + if(Event.current.commandName == "Delete" || Event.current.commandName == "SoftDelete") + { + deletingObject = true; + } + + if (deletingObject) + { + Transform[] transformsSelected = Selection.transforms; + for (int i = 0; i < transformsSelected.Length; i++) + { + Renderer[] renderers = transformsSelected[i].GetComponentsInChildren(); + bool changesDiscarded = overrideData.DiscardChanges(renderers); + + if (changesDiscarded) + { + EditorSceneManager.MarkSceneDirty(scene); + AssetDatabase.SaveAssets(); + } + } + } + } + } + + private bool OnWantsToQuit() + { + bool res = true; + + if(state == State.PREVIEW) + { + bool dialog = EditorUtility.DisplayDialog("Overriding in process", "You are using preview materials. Finish override process before closing Unity", "End override process", "Cancel"); + if (dialog) + { + Close(); + } + + res = false; + } + + return res; + } + + private static void OnHierarchyChanged() + { + + } + + private static void BeforeAssemblyReload() + { + if(overrideData != null) + { + overrideData.EndOverrideProcess(); + } + } + + public override string GetTabName() + { + return TAB_NAME; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/OverrideMaterialsTabDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows/OverrideMaterialsTabDrawer.cs.meta new file mode 100644 index 0000000..5dcf13b --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/OverrideMaterialsTabDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 3ff44cb967a47df41a2c11c4f4bc3bbe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Windows/OverrideMaterialsTabDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/SavePathsTabDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Windows/SavePathsTabDrawer.cs new file mode 100644 index 0000000..26f6c31 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/SavePathsTabDrawer.cs @@ -0,0 +1,77 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class SavePathsTabDrawer : AssetWindowTabDrawer + { + private const string TAB_NAME = "Save Paths"; + + public SavePathsTabDrawer(CommonStyles commonStyles, AllIn13DShaderWindow parentWindow) : base(commonStyles, parentWindow) + {} + + public override void OnEnable() + { + + } + + public override void OnDisable() + { + + } + + public override void Show() + { + + } + + public override void Hide() + { + + } + + public override void EnteredPlayMode() + { + + } + + public override void Draw() + { + GUILayout.Label("Material Save Path", commonStyles.bigLabel); + GUILayout.Space(20); + GUILayout.Label("Select the folder where new Materials will be saved when the Save Material To Folder button of the asset component is pressed", EditorStyles.boldLabel); + GlobalConfiguration.instance.MaterialSavePath = EditorUtils.DrawSelectorFolder(GlobalConfiguration.instance.MaterialSavePath, "New Material Folder"); + + EditorUtils.DrawThinLine(); + GUILayout.Label("Render Material to Image Save Path", commonStyles.bigLabel); + GUILayout.Space(20); + + EditorGUILayout.BeginHorizontal(); + GUILayout.Label("Rendered Image Texture Scale", GUILayout.MaxWidth(190)); + GlobalConfiguration.instance.RenderImageScale = EditorGUILayout.Slider(GlobalConfiguration.instance.RenderImageScale, 0.2f, 5f, GUILayout.MaxWidth(200)); + if (GUILayout.Button("Default Value", GUILayout.MaxWidth(100))) + { + GlobalConfiguration.instance.RenderImageScale = 1f; + } + EditorGUILayout.EndHorizontal(); + + GlobalConfiguration.instance.RenderImageSavePath = EditorUtils.DrawSelectorFolder(GlobalConfiguration.instance.RenderImageSavePath, "New Images Folder"); + EditorUtils.DrawThinLine(); + + GUILayout.Label("Baked Shader Save Path", commonStyles.bigLabel); + GUILayout.Space(20); + GUILayout.Label("Select the folder where baked shaders will be saved when the Bake Shader Keywords button of the material inspector is pressed", EditorStyles.boldLabel); + GlobalConfiguration.instance.BakedShaderSavePath = EditorUtils.DrawSelectorFolder(GlobalConfiguration.instance.BakedShaderSavePath, "New Bake Shader Folder"); + EditorUtils.DrawThinLine(); + + GUILayout.Label("Gradients Save Path", commonStyles.bigLabel); + GUILayout.Space(20); + GlobalConfiguration.instance.GradientsSavePath = EditorUtils.DrawSelectorFolder(GlobalConfiguration.instance.GradientsSavePath, "Gradients Folder"); + } + + public override string GetTabName() + { + return TAB_NAME; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/SavePathsTabDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows/SavePathsTabDrawer.cs.meta new file mode 100644 index 0000000..4c4285b --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/SavePathsTabDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 5dedcd72b9fe8cc46920937a02695a3e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Windows/SavePathsTabDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureCreatorTabDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureCreatorTabDrawer.cs new file mode 100644 index 0000000..f5c18d9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureCreatorTabDrawer.cs @@ -0,0 +1,101 @@ +namespace AllIn13DShader +{ + public class TextureCreatorTabDrawer : AssetWindowTabDrawer + { + private const string TAB_NAME = "Texture Creators"; + + private NormalMapCreatorTool normalMapCreatorTool; + private NormalMapCreatorDrawer normalMapCreatorDrawer; + + private GradientCreatorTool gradientCreatorTool; + private GradientCreatorDrawer gradientCreatorDrawer; + + private AtlasPackerTool atlasPackerTool; + private AtlasPackerDrawer atlasPackerDrawer; + + private NoiseCreatorTool noiseCreatorTool; + private NoiseCreatorDrawer noiseCreatorDrawer; + + private RGBAPackerTool rgbaPackerTool; + private RGBAPackerDrawer rgbaPackerDrawer; + + public TextureCreatorTabDrawer(CommonStyles commonStyles, AllIn13DShaderWindow parentWindow) : base(commonStyles, parentWindow) + { + Initialize(); + } + + private void Initialize() + { + normalMapCreatorTool = new NormalMapCreatorTool(); + normalMapCreatorDrawer = new NormalMapCreatorDrawer(normalMapCreatorTool, commonStyles, Repaint); + + gradientCreatorTool = new GradientCreatorTool(); + gradientCreatorDrawer = new GradientCreatorDrawer(gradientCreatorTool, commonStyles); + + atlasPackerTool = new AtlasPackerTool(); + atlasPackerDrawer = new AtlasPackerDrawer(atlasPackerTool, commonStyles); + + noiseCreatorTool = new NoiseCreatorTool(); + noiseCreatorDrawer = new NoiseCreatorDrawer(noiseCreatorTool, commonStyles); + + rgbaPackerTool = new RGBAPackerTool(); + rgbaPackerDrawer = new RGBAPackerDrawer(rgbaPackerTool, commonStyles); + } + + public override void OnEnable() + { + + } + + public override void OnDisable() + { + + } + + public override void Show() + { + Initialize(); + } + + public override void Hide() + { + + } + + public override void EnteredPlayMode() + { + + } + + public override void Draw() + { + normalMapCreatorDrawer.Draw(); + + EditorUtils.DrawThinLine(); + + gradientCreatorDrawer.Draw(); + + EditorUtils.DrawThinLine(); + + atlasPackerDrawer.Draw(); + + EditorUtils.DrawThinLine(); + + noiseCreatorDrawer.Draw(); + + EditorUtils.DrawThinLine(); + + rgbaPackerDrawer.Draw(); + } + + private void Repaint() + { + parentWindow.Repaint(); + } + + public override string GetTabName() + { + return TAB_NAME; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureCreatorTabDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureCreatorTabDrawer.cs.meta new file mode 100644 index 0000000..60d6ba3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureCreatorTabDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 13ec4b12120f25c43bfae408eec0aa1b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Windows/TextureCreatorTabDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureEditorTabDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureEditorTabDrawer.cs new file mode 100644 index 0000000..fc16b55 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureEditorTabDrawer.cs @@ -0,0 +1,73 @@ +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class TextureEditorTabDrawer : AssetWindowTabDrawer + { + private const string TAB_NAME = "Texture Editor"; + + private TextureEditorTool textureEditorTool; + private TextureEditorValuesDrawer textureEditorValuesDrawer; + + public TextureEditorTabDrawer(CommonStyles commonStyles, AllIn13DShaderWindow parentWindow) : base(commonStyles, parentWindow) + { + textureEditorTool = new TextureEditorTool(); + textureEditorValuesDrawer = new TextureEditorValuesDrawer(); + textureEditorValuesDrawer.Setup(textureEditorTool); + } + + public override void Show() + { + + } + + public override void Hide() + { + + } + public override void OnEnable() + { + + } + + public override void OnDisable() + { + + } + + public override void EnteredPlayMode() + { + + } + + public override void Draw() + { + EditorGUI.BeginChangeCheck(); + textureEditorTool.editorTexInput = EditorGUILayout.ObjectField("Image to Edit", textureEditorTool.editorTexInput, typeof(Texture2D), false, GUILayout.Width(300), GUILayout.Height(50)) as Texture2D; + if (EditorGUI.EndChangeCheck()) + { + if (textureEditorTool.editorTexInput != null) + { + textureEditorTool.Setup(); + } + } + + EditorUtils.DrawThinLine(); + + if (textureEditorTool.editorTex != null) + { + textureEditorValuesDrawer.Draw(); + } + else + { + GUILayout.Label("Please select an Image to Edit above", EditorStyles.boldLabel); + } + } + + public override string GetTabName() + { + return TAB_NAME; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureEditorTabDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureEditorTabDrawer.cs.meta new file mode 100644 index 0000000..556c0d2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/TextureEditorTabDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 7920383ff86b65c498c235aded8484b3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Windows/TextureEditorTabDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsController.cs b/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsController.cs new file mode 100644 index 0000000..d312b31 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsController.cs @@ -0,0 +1,45 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public static class URPSettingsController + { + public static void DisableFeature(string featureToDisable) + { + // Find the shader features file + string[] guids = AssetDatabase.FindAssets("AllIn13DShader_FeaturesURP_Defines"); + if (guids.Length == 0) + { + Debug.LogWarning("AllIn13DShader_FeaturesURP file not found"); + return; + } + + string shaderFeaturesFilePath = AssetDatabase.GUIDToAssetPath(guids[0]); + if (string.IsNullOrEmpty(shaderFeaturesFilePath)) + { + Debug.LogWarning("Could not get path for AllIn13DShader_FeaturesURP file"); + return; + } + + // Read the file content + string fileContent = File.ReadAllText(shaderFeaturesFilePath); + string[] lines = fileContent.Split("\n"); + + string correctedFile = string.Empty; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (line.StartsWith($"#define {featureToDisable}")) + { + line = "//" + line; + } + + correctedFile += line; + } + + File.WriteAllText(shaderFeaturesFilePath, correctedFile); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsController.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsController.cs.meta new file mode 100644 index 0000000..5cdbc41 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsController.cs.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: c95b42002e9c5d24a9ee98ad07f670c9 +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsController.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsDrawer.cs b/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsDrawer.cs new file mode 100644 index 0000000..591a412 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsDrawer.cs @@ -0,0 +1,121 @@ +using System; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn13DShader +{ + public class URPSettingsDrawer : AssetWindowTabDrawer + { + private const string TAB_NAME = "URP Settings"; + + private URPSettings urpSettings; + private URPSettingsUserPref urpSettingsUserPref; + + public URPSettingsDrawer(CommonStyles commonStyles, AllIn13DShaderWindow parentWindow) : base(commonStyles, parentWindow) + { + this.urpSettings = EditorUtils.FindAsset(URPSettings.ASSET_NAME); + this.urpSettingsUserPref = EditorUtils.FindAsset(URPSettingsUserPref.ASSET_NAME); + } + + public override void Draw() + { + GUILayout.Label("Shader Feature Configuration", commonStyles.bigLabel); + EditorGUILayout.HelpBox("Enable/disable shader features to optimize compilation time and editor performance. \n" + + "Hover each feature to get a more detailed tooltip.", MessageType.Info); + + GUILayout.Space(5); + + for(int i = 0; i < urpSettings.configs.Length; i++) + { + EditorGUILayout.BeginHorizontal(); + + URPFeatureConfig urpFeatureConfig = urpSettings.configs[i]; + URPFeatureUserPref urpFeatureUserPref = urpSettingsUserPref.FindPreferenceByID(urpFeatureConfig.shaderDefine); + if(urpFeatureUserPref == null) + { + continue; + } + + + GUIContent toggleContent = new GUIContent(urpFeatureConfig.displayName, urpFeatureConfig.tooltip); + urpFeatureUserPref.enabled = EditorGUILayout.ToggleLeft(toggleContent, urpFeatureUserPref.enabled); + + EditorGUILayout.EndHorizontal(); + } + + GUILayout.Space(10); + + EditorGUILayout.BeginHorizontal(); + if(GUILayout.Button("Apply Changes")) + { + ApplyFeatureChanges(); + } + + if(GUILayout.Button("Reset to Defaults")) + { + ResetToDefaults(); + } + EditorGUILayout.EndHorizontal(); + + GUILayout.Space(20); + EditorUtils.DrawThinLine(); + + GUILayout.Label("Configure AllIn13D to work correctly with URP", commonStyles.bigLabel); + if (GUILayout.Button("Configure")) + { +#if ALLIN13DSHADER_URP + URPConfigurator.Configure(forceConfigure: true); +#endif + } + } + + public override void Hide() + { + + } + + public override void Show() + { + + } + + public override void OnDisable() + { + + } + + public override void OnEnable() + { + + } + + public override void EnteredPlayMode() + { + + } + + private void ApplyFeatureChanges() + { + URPDefinesFileCreator.CreateFile(urpSettings, urpSettingsUserPref); + AssetDatabase.Refresh(); + } + + private void ResetToDefaults() + { + + for(int i = 0; i < urpSettingsUserPref.preferences.Length; i++) + { + URPFeatureUserPref preference = urpSettingsUserPref.preferences[i]; + URPFeatureConfig urpFeatureConfig = urpSettings.FindConfigByID(preference.id); + + urpSettingsUserPref.preferences[i].Init(urpFeatureConfig); + } + } + + public override string GetTabName() + { + return TAB_NAME; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsDrawer.cs.meta b/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsDrawer.cs.meta new file mode 100644 index 0000000..e879b76 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 638a6d02f9a0f524386897efd05ce5c9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Editor/Windows/URPSettingsDrawer.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps.meta b/Assets/Plugins/AllIn13DShader/Matcaps.meta new file mode 100644 index 0000000..56dd849 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 53dce72bb15cf064ebcd9085a1f8013d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap1.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap1.png new file mode 100644 index 0000000..5e5e5e9 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap1.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap1.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap1.png.meta new file mode 100644 index 0000000..7cf4467 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap1.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 4ca93af30a0abfa4bb10ee16b6193232 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap1.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap10.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap10.png new file mode 100644 index 0000000..cab4a0f Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap10.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap10.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap10.png.meta new file mode 100644 index 0000000..17632eb --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap10.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 5a17f5900f795e647babd6a52dd0d00f +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 1 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap10.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap11.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap11.png new file mode 100644 index 0000000..f2948be Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap11.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap11.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap11.png.meta new file mode 100644 index 0000000..3237a94 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap11.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 4fe4d1b99a8d68044b706695d98d68f5 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap11.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap12.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap12.png new file mode 100644 index 0000000..f9e52d6 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap12.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap12.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap12.png.meta new file mode 100644 index 0000000..ed24bd4 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap12.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 7e63fa67497d8c144aee8456d2fb9bfe +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap12.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap13.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap13.png new file mode 100644 index 0000000..85fb199 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap13.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap13.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap13.png.meta new file mode 100644 index 0000000..cf4df42 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap13.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 7a970b660a6d19e46894f456130d1aba +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap13.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap14.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap14.png new file mode 100644 index 0000000..4d09827 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap14.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap14.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap14.png.meta new file mode 100644 index 0000000..b80bb65 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap14.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: a9bce1321ad609746bf16e04941d2c64 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap14.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap15.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap15.png new file mode 100644 index 0000000..f9a1581 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap15.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap15.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap15.png.meta new file mode 100644 index 0000000..3685ad3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap15.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 3adbe1051547387498ddfe18854b6d7c +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap15.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap16.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap16.png new file mode 100644 index 0000000..f9d3244 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap16.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap16.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap16.png.meta new file mode 100644 index 0000000..14c36ea --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap16.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: bb867bb66f874c344b95913e42742b6b +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap16.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap17.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap17.png new file mode 100644 index 0000000..e4b890a Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap17.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap17.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap17.png.meta new file mode 100644 index 0000000..e792971 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap17.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 5c7c59fff11467443bb77e1712a30bf7 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap17.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap18.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap18.png new file mode 100644 index 0000000..f307ca1 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap18.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap18.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap18.png.meta new file mode 100644 index 0000000..4a94d9d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap18.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 15843af64ad2270478da0b07bbfb3186 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap18.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap19.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap19.png new file mode 100644 index 0000000..820829f Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap19.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap19.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap19.png.meta new file mode 100644 index 0000000..e1ac312 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap19.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: e427c7ed8ea262b47a9285168bba5931 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap19.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap20.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap20.png new file mode 100644 index 0000000..5118907 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap20.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap20.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap20.png.meta new file mode 100644 index 0000000..08798b1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap20.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 31215cbe447c15344b6da5f2a30c29d0 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap20.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap21.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap21.png new file mode 100644 index 0000000..2553d71 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap21.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap21.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap21.png.meta new file mode 100644 index 0000000..8ee6ed9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap21.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 8b52205439d608847939c878d5f920f0 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap21.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap22.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap22.png new file mode 100644 index 0000000..d68b052 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap22.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap22.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap22.png.meta new file mode 100644 index 0000000..fb393aa --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap22.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: d480d59f6f5acd94d82a3aeb852ec967 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap22.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap23.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap23.png new file mode 100644 index 0000000..fae2467 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap23.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap23.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap23.png.meta new file mode 100644 index 0000000..4479c4e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap23.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 7cbc844f48c94cc4986e9ae7e88ca0d5 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap23.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap24.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap24.png new file mode 100644 index 0000000..cc9ca6e Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap24.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap24.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap24.png.meta new file mode 100644 index 0000000..7b61eaa --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap24.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 6c869805944cb204ab71492b24e70414 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap24.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap25.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap25.png new file mode 100644 index 0000000..95bc53f Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap25.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap25.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap25.png.meta new file mode 100644 index 0000000..cda7abb --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap25.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 6685b7db212ff0a4eb8c4f1b70c302a6 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap25.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap26.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap26.png new file mode 100644 index 0000000..3b52bc6 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap26.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap26.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap26.png.meta new file mode 100644 index 0000000..8d68f23 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap26.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: df8b2a7e5b824a24fb2054edb471bede +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap26.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap27.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap27.png new file mode 100644 index 0000000..4a36fa6 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap27.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap27.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap27.png.meta new file mode 100644 index 0000000..bfbb4b0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap27.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 53920fc775e27e14cbc5d60fe9de4835 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap27.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap28.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap28.png new file mode 100644 index 0000000..3ada039 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap28.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap28.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap28.png.meta new file mode 100644 index 0000000..e33d4c9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap28.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: bb7e91a8b0d4fdc43a6fcfaeea95eea7 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap28.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap29.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap29.png new file mode 100644 index 0000000..380fd2d Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap29.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap29.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap29.png.meta new file mode 100644 index 0000000..27c715d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap29.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: db7da98fa5358254ea8c55df24f25459 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap29.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap3.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap3.png new file mode 100644 index 0000000..be525fe Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap3.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap3.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap3.png.meta new file mode 100644 index 0000000..40d1f40 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap3.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: cbbed00d7872cf440937681259040818 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap3.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap30.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap30.png new file mode 100644 index 0000000..b5660ac Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap30.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap30.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap30.png.meta new file mode 100644 index 0000000..e607463 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap30.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 6362604a08a77ce47ac46aa943db6e74 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap30.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap31.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap31.png new file mode 100644 index 0000000..aefa2fc Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap31.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap31.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap31.png.meta new file mode 100644 index 0000000..39fa298 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap31.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 42854ada7fb551c45a4ab25eeeba884e +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap31.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap32.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap32.png new file mode 100644 index 0000000..8883f33 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap32.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap32.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap32.png.meta new file mode 100644 index 0000000..1d0b788 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap32.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 14add619167ff784687ed113a8ea76db +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap32.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap33.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap33.png new file mode 100644 index 0000000..53ccb75 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap33.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap33.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap33.png.meta new file mode 100644 index 0000000..fa0bc02 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap33.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 7e3265eb9cf6d8740824e72287dc4109 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap33.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap34.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap34.png new file mode 100644 index 0000000..a460a22 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap34.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap34.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap34.png.meta new file mode 100644 index 0000000..42e8167 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap34.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 2aa9381b423e896448e549f7d48f44e1 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap34.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap35.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap35.png new file mode 100644 index 0000000..ca30148 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap35.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap35.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap35.png.meta new file mode 100644 index 0000000..758d90c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap35.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: ed504ec57f3e54448ab8ae02f44d9fae +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap35.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap36.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap36.png new file mode 100644 index 0000000..35ad2e9 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap36.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap36.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap36.png.meta new file mode 100644 index 0000000..44edc11 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap36.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 04ba2e7ecb07b4a49b6311dee9cd7dd9 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap36.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap4.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap4.png new file mode 100644 index 0000000..53bd4be Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap4.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap4.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap4.png.meta new file mode 100644 index 0000000..979ad66 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap4.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: ef180fef6138e0d4c8aab4a13f5661cc +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap4.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap5.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap5.png new file mode 100644 index 0000000..c07aa12 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap5.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap5.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap5.png.meta new file mode 100644 index 0000000..79eef6a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap5.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 0013ca04ccd4f4f48a060a4201d78576 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap5.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap6.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap6.png new file mode 100644 index 0000000..604e4d6 Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap6.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap6.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap6.png.meta new file mode 100644 index 0000000..31877ae --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap6.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: a063a187686537e46adc4d4489e1c33d +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap6.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap7.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap7.png new file mode 100644 index 0000000..83f7b6b Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap7.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap7.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap7.png.meta new file mode 100644 index 0000000..483947f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap7.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 65589145c4eb3404492d48a43c212dec +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap7.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap8.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap8.png new file mode 100644 index 0000000..d1d519f Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap8.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap8.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap8.png.meta new file mode 100644 index 0000000..8b490bc --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap8.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 532ba8f31a5e9a9459437ed0449bf4a5 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap8.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap9.png b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap9.png new file mode 100644 index 0000000..c1cca8d Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap9.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/Matcap9.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap9.png.meta new file mode 100644 index 0000000..696f0a9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/Matcap9.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: 074447c8b479f664aa5062128d3f0305 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/Matcap9.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/matCap2.png b/Assets/Plugins/AllIn13DShader/Matcaps/matCap2.png new file mode 100644 index 0000000..1efbc0f Binary files /dev/null and b/Assets/Plugins/AllIn13DShader/Matcaps/matCap2.png differ diff --git a/Assets/Plugins/AllIn13DShader/Matcaps/matCap2.png.meta b/Assets/Plugins/AllIn13DShader/Matcaps/matCap2.png.meta new file mode 100644 index 0000000..24ea144 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Matcaps/matCap2.png.meta @@ -0,0 +1,130 @@ +fileFormatVersion: 2 +guid: da3fd89ef6a993b4f9a10e680e476592 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Matcaps/matCap2.png + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Scripts.meta b/Assets/Plugins/AllIn13DShader/Scripts.meta new file mode 100644 index 0000000..64fce0a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4103463142ff186439ca7abc86e33f17 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderComponent.cs b/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderComponent.cs new file mode 100644 index 0000000..bd0ad4f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderComponent.cs @@ -0,0 +1,104 @@ +#if UNITY_EDITOR +using UnityEditor; +#endif + +using UnityEngine; + +namespace AllIn13DShader +{ + [ExecuteInEditMode] + [DisallowMultipleComponent] + [AddComponentMenu("AllIn13DShader/AddAllIn13DShader")] + public class AllIn13DShaderComponent : MonoBehaviour + { + public Renderer currRenderer; + public Material currMaterial + { + get + { + return currRenderer.sharedMaterial; + } + set + { + currRenderer.sharedMaterial = value; + } + } + +#if UNITY_EDITOR + public void NewCleanMaterial(Shader shader, Material matPreset) + { + Material previousMat = currMaterial; + + currMaterial = new Material(shader); + currMaterial.CopyMatchingPropertiesFromMaterial(matPreset); + + string materialName = currMaterial.name; + int nameStartIndex = materialName.LastIndexOf("/"); + if(nameStartIndex >= 0) + { + materialName = materialName.Substring(nameStartIndex + 1); + } + + currMaterial.name = $"MAT_{materialName}"; + } + + public void CleanMaterial() + { + currMaterial = new Material(Shader.Find(ConstantsRuntime.STANDARD_SHADER_NAME)); + } + + public bool CheckValidComponent() + { + bool res = true; + + bool dirty = false; + if (currRenderer == null || currMaterial == null) + { + res = res && TryGetComponent(out currRenderer); + dirty = true; + } + + if (dirty && res) + { + currRenderer = GetComponent(); + + EditorUtility.SetDirty(this); + + if(currMaterial != null) + { + EditorUtility.SetDirty(currMaterial); + } + } + + return res; + } + + public void ApplyMaterialToChildren() + { + ApplyMaterialRecursively(transform, currMaterial); + } + + public Material DuplicateCurrentMaterial() + { + currMaterial = new Material(currMaterial); + return currMaterial; + } + + private void ApplyMaterialRecursively(Transform tr, Material mat) + { + bool existsMeshRenderer = tr.TryGetComponent(out currRenderer); + + if (existsMeshRenderer) + { + currRenderer.sharedMaterial = mat; + } + + int childCount = tr.childCount; + for(int i = 0; i < childCount; i++) + { + ApplyMaterialRecursively(tr.GetChild(i), mat); + } + } +#endif + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderComponent.cs.meta b/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderComponent.cs.meta new file mode 100644 index 0000000..b2c8bec --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderComponent.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 09fb2c5f145047846ac8e94ce0994dbb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderComponent.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderRandomTimeSeed.cs b/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderRandomTimeSeed.cs new file mode 100644 index 0000000..7d513b3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderRandomTimeSeed.cs @@ -0,0 +1,24 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [ExecuteInEditMode] + public class AllIn13DShaderRandomTimeSeed : MonoBehaviour + { + [SerializeField] private float minSeedValue = 0; + [SerializeField] private float maxSeedValue = 100f; + + private void Start() + { + RefreshTimingSeed(); + } + + [ContextMenu("Refresh Timing Seed")] + private void RefreshTimingSeed() + { + MaterialPropertyBlock properties = new MaterialPropertyBlock(); + properties.SetFloat("_TimingSeed", Random.Range(minSeedValue, maxSeedValue)); + GetComponent().SetPropertyBlock(properties); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderRandomTimeSeed.cs.meta b/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderRandomTimeSeed.cs.meta new file mode 100644 index 0000000..406d0b5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderRandomTimeSeed.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 8302f7da0ee1d6848bcadb44b88c6626 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Scripts/AllIn13DShaderRandomTimeSeed.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Scripts/AllIn1DepthColoringProperties.cs b/Assets/Plugins/AllIn13DShader/Scripts/AllIn1DepthColoringProperties.cs new file mode 100644 index 0000000..5ab0267 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/AllIn1DepthColoringProperties.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [CreateAssetMenu(menuName = "AllIn13DShader/Others/Depth Coloring Properties", fileName = "DepthColoringProperties.asset")] + public class AllIn1DepthColoringProperties : ScriptableObject + { + public float depthColoringMinDepth; + [Range(0.1f, 1.5f)] public float fallOff; + public Texture2D depthColoringGradientTex; + public float depthZoneLength; + + private readonly int globalMinDepth = Shader.PropertyToID("global_MinDepth"); + private readonly int globalDepthZoneLength = Shader.PropertyToID("global_DepthZoneLength"); + private readonly int globalDepthGradient = Shader.PropertyToID("global_DepthGradient"); + private readonly int globalDepthGradientFallOff = Shader.PropertyToID("global_DepthGradientFallOff"); + + public void ApplyValues() + { + Shader.SetGlobalFloat(globalMinDepth, depthColoringMinDepth); + Shader.SetGlobalFloat(globalDepthZoneLength, depthZoneLength); + Shader.SetGlobalFloat(globalDepthGradientFallOff, fallOff); + Shader.SetGlobalTexture(globalDepthGradient, depthColoringGradientTex); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Scripts/AllIn1DepthColoringProperties.cs.meta b/Assets/Plugins/AllIn13DShader/Scripts/AllIn1DepthColoringProperties.cs.meta new file mode 100644 index 0000000..a5b6d6e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/AllIn1DepthColoringProperties.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 550a4f83cc82e43499a5efe7e94a4f5a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Scripts/AllIn1DepthColoringProperties.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Scripts/ConstantsRuntime.cs b/Assets/Plugins/AllIn13DShader/Scripts/ConstantsRuntime.cs new file mode 100644 index 0000000..20c3291 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/ConstantsRuntime.cs @@ -0,0 +1,23 @@ +namespace AllIn13DShader +{ + public static class ConstantsRuntime + { + //Special Properties + public const string GLOBAL_PROPERTY_GLOBAL_TIME = "allIn13DShader_globalTime"; + +#if UNITY_EDITOR + + public const string SESSION_KEY_ROOT_PLUGIN_PATH = "AllIn13DShader_sessionKey_rootPluginPath"; + + //Standard Shader +#if ALLIN13DSHADER_BIRP + public const string STANDARD_SHADER_NAME = "Standard"; +#elif ALLIN13DSHADER_URP + public const string STANDARD_SHADER_NAME = "Universal Render Pipeline/Lit"; +#else + public const string STANDARD_SHADER_NAME = "Standard"; +#endif + +#endif + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Scripts/ConstantsRuntime.cs.meta b/Assets/Plugins/AllIn13DShader/Scripts/ConstantsRuntime.cs.meta new file mode 100644 index 0000000..66157c5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/ConstantsRuntime.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 3ea460bdd0e63b64e8d01c3ed5f2d97e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Scripts/ConstantsRuntime.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Scripts/DepthColoringCamera.cs b/Assets/Plugins/AllIn13DShader/Scripts/DepthColoringCamera.cs new file mode 100644 index 0000000..7e7893f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/DepthColoringCamera.cs @@ -0,0 +1,39 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [ExecuteInEditMode] + public class DepthColoringCamera : MonoBehaviour + { + public Camera cam; + public AllIn1DepthColoringProperties depthColoringProperties; + + private void OnEnable() + { + if(depthColoringProperties != null) + { + depthColoringProperties.ApplyValues(); + } + } + +#if UNITY_EDITOR + private void Update() + { + Update_Editor(); + } + + private void Reset() + { + cam = GetComponent(); + } + + private void Update_Editor() + { + if(cam != null) + { + cam.depthTextureMode = DepthTextureMode.Depth; + } + } +#endif + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Scripts/DepthColoringCamera.cs.meta b/Assets/Plugins/AllIn13DShader/Scripts/DepthColoringCamera.cs.meta new file mode 100644 index 0000000..b07974b --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/DepthColoringCamera.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: bb429cb35d67af14c998db9b8ff58396 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Scripts/DepthColoringCamera.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Scripts/FastLightConfigurator.cs b/Assets/Plugins/AllIn13DShader/Scripts/FastLightConfigurator.cs new file mode 100644 index 0000000..77effd9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/FastLightConfigurator.cs @@ -0,0 +1,62 @@ +using System.IO; +using UnityEngine; + +namespace AllIn13DShader +{ + [ExecuteInEditMode] + public class FastLightConfigurator : MonoBehaviour + { + private readonly int global_lightDirection = Shader.PropertyToID("global_lightDirection"); + private readonly int global_lightColor = Shader.PropertyToID("global_lightColor"); + + public Color lightColor = Color.white; + + private void Update() + { + Shader.SetGlobalVector(global_lightDirection, -transform.forward); + Shader.SetGlobalColor(global_lightColor, lightColor); + } + +#if UNITY_EDITOR + private void OnDrawGizmos() + { + string gizmosFolderPath = UnityEditor.SessionState.GetString(ConstantsRuntime.SESSION_KEY_ROOT_PLUGIN_PATH, string.Empty); + if (!string.IsNullOrEmpty(gizmosFolderPath)) + { + string iconPath = Path.Combine(gizmosFolderPath, "Editor\\Gizmos\\Fast_Light_Icon.png"); + iconPath = iconPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + Gizmos.DrawIcon(transform.position, iconPath, false, lightColor); + } + } + + private void OnDrawGizmosSelected() + { + Color rayColor = lightColor; + rayColor.a = 0.25f; + + int numRays = 12; + float angle = 360f / numRays; + float radius = 0.5f; + float rayLength = 3f; + Vector3 rayInit = transform.position + transform.up * radius; + + Gizmos.color = rayColor; + for (int i = 0; i < numRays; i++) + { + Gizmos.DrawRay(rayInit, transform.forward * rayLength); + + Vector3 vec = rayInit - transform.position; + Vector3 rotatedVec = Quaternion.AngleAxis(angle, transform.forward) * vec; + + rayInit = transform.position + rotatedVec; + } + } + + private void Reset() + { + Light thisLight = GetComponent(); + if(thisLight != null) lightColor = thisLight.color; + } +#endif + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Scripts/FastLightConfigurator.cs.meta b/Assets/Plugins/AllIn13DShader/Scripts/FastLightConfigurator.cs.meta new file mode 100644 index 0000000..51359f0 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/FastLightConfigurator.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: bd4409434c8db9244bf9b01281077df9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Scripts/FastLightConfigurator.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Scripts/ShaderGlobalTimeController.cs b/Assets/Plugins/AllIn13DShader/Scripts/ShaderGlobalTimeController.cs new file mode 100644 index 0000000..262c067 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/ShaderGlobalTimeController.cs @@ -0,0 +1,20 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [ExecuteInEditMode] + public class ShaderGlobalTimeController : MonoBehaviour + { + private readonly int globalTimePropertyID = Shader.PropertyToID(ConstantsRuntime.GLOBAL_PROPERTY_GLOBAL_TIME); + private Vector4 timeVector; + + private void Update() + { + timeVector.x = Time.unscaledTime / 20f; + timeVector.y = Time.unscaledTime; + timeVector.z = Time.unscaledTime * 2f; + timeVector.w = Time.unscaledTime * 3f; + Shader.SetGlobalVector(globalTimePropertyID, timeVector); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Scripts/ShaderGlobalTimeController.cs.meta b/Assets/Plugins/AllIn13DShader/Scripts/ShaderGlobalTimeController.cs.meta new file mode 100644 index 0000000..d66bfa6 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/ShaderGlobalTimeController.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 736e2efc20149b14183cb7af7a304732 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Scripts/ShaderGlobalTimeController.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Scripts/ShadowsConfigurator.cs b/Assets/Plugins/AllIn13DShader/Scripts/ShadowsConfigurator.cs new file mode 100644 index 0000000..398615d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/ShadowsConfigurator.cs @@ -0,0 +1,24 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [ExecuteInEditMode] + public class ShadowsConfigurator : MonoBehaviour + { + public Color shadowColor = Color.black; + + private readonly int shadowColorPropID = Shader.PropertyToID("global_shadowColor"); + +#if UNITY_EDITOR + public void Update() + { + SetupShadowColor(); + } +#endif + + public void SetupShadowColor() + { + Shader.SetGlobalColor(shadowColorPropID, shadowColor); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Scripts/ShadowsConfigurator.cs.meta b/Assets/Plugins/AllIn13DShader/Scripts/ShadowsConfigurator.cs.meta new file mode 100644 index 0000000..e7fdf0a --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/ShadowsConfigurator.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 74c2a9bafe054594dba7f6110a0e0fa3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Scripts/ShadowsConfigurator.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Scripts/WindController.cs b/Assets/Plugins/AllIn13DShader/Scripts/WindController.cs new file mode 100644 index 0000000..27f6bb9 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/WindController.cs @@ -0,0 +1,102 @@ +using UnityEngine; + +namespace AllIn13DShader +{ + [ExecuteInEditMode] + public class WindController : MonoBehaviour + { + private readonly int MATPROP_GLOBAL_WIND_NOISE_TEX = Shader.PropertyToID("global_windNoiseTex"); + private readonly int MATPROP_GLOBAL_WIND_FORCE = Shader.PropertyToID("global_windForce"); + private readonly int MATPROP_GLOBAL_NOISE_SPEED = Shader.PropertyToID("global_noiseSpeed"); + private readonly int MATPROP_GLOBAL_WIND_DIR = Shader.PropertyToID("global_windDir"); + private readonly int MATPROP_GLOBAL_USE_WIND_DIR = Shader.PropertyToID("global_useWindDir"); + private readonly int MATPROP_GLOBAL_MIN_WIND_VALUE = Shader.PropertyToID("global_minWindValue"); + private readonly int MATPROP_GLOBAL_MAX_WIND_VALUE = Shader.PropertyToID("global_maxWindValue"); + private readonly int MATPROP_GLOBAL_WIND_WORLD_SIZE = Shader.PropertyToID("global_windWorldSize"); + + [Header("General")] + [Tooltip("Overall strength of the wind effect. Higher values create stronger wind displacement.")] + [Range(0f, 3f)] public float windForce = 1f; + + [Tooltip("Speed of noise texture scrolling (X,Y). Higher values create faster wind movement.")] + public Vector2 noiseSpeed = new Vector2(12f, 6f); + + [Tooltip("When enabled, wind can push objects in both positive and negative directions. When disabled, wind only pushes in the positive direction.")] + public bool bidirectionalWind = true; + + [Tooltip("When enabled, wind direction is determined by this GameObject's forward direction. When disabled, wind affects all directions equally.")] + public bool useWindDir = false; + + [Header("World Size")] + [Tooltip("Scale of the noise texture in world space. Larger values spread the wind pattern across a bigger area.")] + public float worldSize = 50f; + + [Header("Noise")] + [Tooltip("Texture used to generate wind displacement patterns. RGB channels control displacement in respective directions.")] + public Texture2D windNoise; + + public void Update() + { + ApplyWindValues(); + } + + public void ApplyWindValues() + { + if(windNoise != null) + { + Shader.SetGlobalTexture(MATPROP_GLOBAL_WIND_NOISE_TEX, windNoise); + } + + Shader.SetGlobalFloat(MATPROP_GLOBAL_WIND_FORCE, windForce); + Shader.SetGlobalVector(MATPROP_GLOBAL_NOISE_SPEED, noiseSpeed); + + Vector3 correctedWindDir = useWindDir ? transform.forward : Vector3.one; + float useWindDirFloat = useWindDir ? 1f : 0f; + Shader.SetGlobalFloat(MATPROP_GLOBAL_USE_WIND_DIR, useWindDirFloat); + Shader.SetGlobalVector(MATPROP_GLOBAL_WIND_DIR, correctedWindDir); + + float minWindValue = bidirectionalWind ? -1f : 0f; + Shader.SetGlobalFloat(MATPROP_GLOBAL_MIN_WIND_VALUE, minWindValue); + Shader.SetGlobalFloat(MATPROP_GLOBAL_MAX_WIND_VALUE, 1f); + Shader.SetGlobalFloat(MATPROP_GLOBAL_WIND_WORLD_SIZE, worldSize); + } + +#if UNITY_EDITOR + public void OnDrawGizmos() + { + string gizmosFolderPath = UnityEditor.SessionState.GetString(ConstantsRuntime.SESSION_KEY_ROOT_PLUGIN_PATH, string.Empty); + if (!string.IsNullOrEmpty(gizmosFolderPath)) + { + string iconPath = System.IO.Path.Combine(gizmosFolderPath, "Editor\\Gizmos\\GizmoIcon_Wind.png"); + iconPath = iconPath.Replace(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar); + Gizmos.DrawIcon(transform.position, iconPath, false, Color.cyan); + } + } + + private void OnDrawGizmosSelected() + { + if(!useWindDir) { return; } + + Color rayColor = Color.cyan; + rayColor.a = 0.25f; + + int numRays = 12; + float angle = 360f / numRays; + float radius = 0.5f; + float rayLength = 3f; + Vector3 rayInit = transform.position + transform.up * radius; + + Gizmos.color = rayColor; + for (int i = 0; i < numRays; i++) + { + Gizmos.DrawRay(rayInit, transform.forward * rayLength); + + Vector3 vec = rayInit - transform.position; + Vector3 rotatedVec = Quaternion.AngleAxis(angle, transform.forward) * vec; + + rayInit = transform.position + rotatedVec; + } + } +#endif + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Scripts/WindController.cs.meta b/Assets/Plugins/AllIn13DShader/Scripts/WindController.cs.meta new file mode 100644 index 0000000..bf4ef27 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Scripts/WindController.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 0fc862a3a3f744b41ae4abebf6a3bd81 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Scripts/WindController.cs + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders.meta b/Assets/Plugins/AllIn13DShader/Shaders.meta new file mode 100644 index 0000000..f9f87dd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 311410ec0f3d5164cbc273b1ef45cece +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders.meta b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders.meta new file mode 100644 index 0000000..731be49 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 30b7a45d77d684f4f8f64eac5c4e102e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader.shader b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader.shader new file mode 100644 index 0000000..07f8175 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader.shader @@ -0,0 +1,745 @@ +Shader "AllIn13DShader/AllIn13DShader" +{ + Properties + { + /**/ + _RenderPreset("Render Preset", Float) = 1 + [AdvancedProperty]_AdvancedConfigurationEnabled("Show Advanced Configuration", Float) = 0 + [Enum(UnityEngine.Rendering.BlendMode)]_BlendSrc ("Blend mode Source", Float) = 1 + [Enum(UnityEngine.Rendering.BlendMode)]_BlendDst ("Blend mode Destination", Float) = 0 + [AdvancedProperty][Enum(UnityEngine.Rendering.CullMode)]_CullingMode("Culling Mode", Float) = 2 + [AdvancedProperty][Enum(Off, 0, On, 1)]_ZWrite("Depth Write", float) = 1.0 + [AdvancedProperty][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestMode("Z Test Mode", float) = 4 + [AdvancedProperty][Enum(UnityEngine.Rendering.ColorWriteMask)]_ColorMask("Color Write Mask", float) = 15 + [AdvancedProperty][Toggle(_FOG_ON)] _FogOn("Fog On", Float) = 0 + [AdvancedProperty][Toggle(_SPHERIZE_NORMALS_ON)]_SpherizeNormals("Spherize Normals", Float) = 0.0 + [AdvancedProperty][Toggle(_USE_CUSTOM_TIME)] _UseCustomTime("Use Custom Time", Float) = 0 + + [SingleProperty]_MainTex ("Main Texture", 2D) = "white" {} + [SingleProperty]_Color("Color", Color) = (1, 1, 1, 1) + [SingleProperty]_GeneralAlpha("General Alpha", Range(0, 1)) = 1.0 + + //Color Ramp + [Effect(EffectID# COLOR_RAMP, GroupID# ColorEffects, CustomDrawer# COLOR_RAMP_EFFECT_DRAWER)][Toggle(_COLOR_RAMP_ON)]_ColorRampOn("Color Ramp", Float) = 0 + [EffectProperty(ParentEffect# COLOR_RAMP, Keywords(_COLOR_RAMP_ON), AllowReset# False)][KeywordEnum(BeforeLighting, AfterLighting)]_ColorRampLightingStage("Stage", Float) = 0.0 + [EffectProperty(COLOR_RAMP)][AllIn13DShaderGradientDrawer]_ColorRampTex("Color Ramp Tex", 2D) = "white" {} + [EffectProperty(COLOR_RAMP)]_ColorRampLuminosity("Color Ramp Luminosity", Range(0, 1)) = 0 + [EffectProperty(COLOR_RAMP)]_ColorRampBlend("Color Ramp Blend", Range(0, 1)) = 1 + [EffectProperty(COLOR_RAMP)]_ColorRampTiling("Tiling", Range(0.01, 10)) = 1.0 + [EffectProperty(COLOR_RAMP)]_ColorRampScrollSpeed("Scroll Speed", Float) = 0.0 + + //Lighting + [Effect(EffectID# LIGHTMODEL, GroupID# Lighting, ExtraPasses# (FORWARD_ADD))][KeywordEnum(None, Classic, Toon, ToonRamp, HalfLambert, FakeGI, FastLighting)] _LightModel ("Light Model", Float) = 1 + [EffectProperty(LIGHTMODEL, TOON)]_ToonCutoff("Toon Cutoff", Range(0, 1)) = 0.5 + [EffectProperty(LIGHTMODEL, TOON)]_ToonSmoothness("Toon Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(LIGHTMODEL, TOONRAMP)][AllIn13DShaderGradientDrawer]_ToonRamp("Toon Ramp", 2D) = "white" {} + [EffectProperty(LIGHTMODEL, HALFLAMBERT)]_HalfLambertWrap("Half Lambert", Range(0, 1)) = 1 + [EffectProperty(LIGHTMODEL, FAKEGI)]_HardnessFakeGI("Fake GI Hardness", Range(0, 1)) = 0.75 + + //Shading Model + [Effect(EffectID# SHADINGMODEL, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(Basic, PBR)] _ShadingModel("Shading Model", Float) = 0 + [EffectProperty(SHADINGMODEL, PBR)]_Metallic("Metallic", Range(0, 1)) = 0 + [EffectProperty(SHADINGMODEL, PBR)]_Smoothness("Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(ParentEffect# SHADINGMODEL, Keywords(_SHADINGMODEL_PBR), AllowReset# True)][Toggle(_METALLIC_MAP_ON)]_MetallicMapOn("Use Metallic(R) / Smoothness(A) Map?", Float) = 0.0 + [EffectProperty(ParentEffect# SHADINGMODEL, KeywordsOp# AND, Keywords(_SHADINGMODEL_PBR, _METALLIC_MAP_ON), AllowReset# True)]_MetallicMap("Metallic Map", 2D) = "white" {} + + //Specular + [Effect(EffectID# SPECULARMODEL, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(None, Classic, Toon, Anisotropic, AnisotropicToon)]_SpecularModel ("Specular Model", Float) = 0 + [EffectProperty(SPECULARMODEL, CLASSIC, TOON, ANISOTROPIC, ANISOTROPICTOON)]_SpecularAtten("Specular Attenuation", Range(0, 1)) = 0.5 + [EffectProperty(ParentEffect# SPECULARMODEL, IncompatibleWithKws(_SHADINGMODEL_PBR), Keywords(_SPECULARMODEL_CLASSIC, _SPECULARMODEL_TOON), AllowReset# True)]_Shininess("Shininess", Range(0.01, 25)) = 16.0 + [EffectProperty(ParentEffect# SPECULARMODEL, IncompatibleWithKws(_SHADINGMODEL_PBR), Keywords(_SPECULARMODEL_ANISOTROPIC, _SPECULARMODEL_ANISOTROPICTOON), AllowReset# True)]_AnisoShininess("Aniso Shininess", Range(0, 1)) = 0.85 + [EffectProperty(SPECULARMODEL, TOON, ANISOTROPICTOON)]_SpecularToonCutoff("Specular Toon Cutoff", Range(0, 1)) = 0.35 + [EffectProperty(SPECULARMODEL, TOON, ANISOTROPICTOON)]_SpecularToonSmoothness("Specular Toon Smoothness", Range(0, 1)) = 0.0 + [EffectProperty(SPECULARMODEL, CLASSIC, TOON, ANISOTROPIC, ANISOTROPICTOON)]_SpecularMap("Specular Map", 2D) = "white" {} + [EffectProperty(SPECULARMODEL, ANISOTROPIC, ANISOTROPICTOON)]_Anisotropy("Anisotropy", Range(-1, 1)) = 0.45 + + //Reflections + [Effect(EffectID# REFLECTIONS, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(None, Classic, Toon)]_Reflections("Reflections", Float) = 0.0 + [EffectProperty(REFLECTIONS, TOON)]_ToonFactor("Toon Factor", Range(0, 1)) = 0 + [EffectProperty(REFLECTIONS, CLASSIC, TOON)]_ReflectionsAtten("Attenuation", Range(0, 1)) = 0.5 + + //Normal Map + [Effect(EffectID# NORMAL_MAP, GroupID# Lighting, DependentOn# LIGHTMODEL, CustomDrawer# NORMAL_MAP_EFFECT_DRAWER)][Toggle(_NORMAL_MAP_ON)]_NormalMapEnabled("Normal Map", Float) = 0 + [NoScaleOffset][EffectProperty(NORMAL_MAP)]_NormalMap("Normal Map", 2D) = "bump" {} + [EffectProperty(NORMAL_MAP)]_NormalStrength("Normal Strength", Range(0.0, 10.0)) = 1.0 + + //Flat Normals + [Effect(EffectID# FLAT_NORMALS, GroupID# Lighting, DependentOn# LIGHTMODEL)][Toggle(_FLAT_NORMALS_ON)]_FlatNormalsEnabled("Flat Normals", Float) = 0 + [EffectProperty(FLAT_NORMALS)]_FlatNormalsBlend("Blending", Range(0, 1)) = 1.0 + + //Custom Shadow Color + [Effect(EffectID# CUSTOM_SHADOW_COLOR, GroupID# Lighting)][Toggle(_CUSTOM_SHADOW_COLOR_ON)]_CustomShadowColorOn("Custom Shadow Color", Float) = 0 + + //Lightmaps + [Effect(EffectID# AFFECTED_BY_LIGHTMAPS, GroupID# Lighting)][Toggle(_AFFECTED_BY_LIGHTMAPS_ON)]_AffectedByLightmaps("Affected by lightmaps", Float) = 0 + [EffectProperty(AFFECTED_BY_LIGHTMAPS)][Toggle(_LIGHTMAP_COLOR_CORRECTION_ON)]_LightmapColorCorrection("Lightmap Color Correction?", Float) = 0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueShiftLM("Hue Shift", Range(0, 360)) = 0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueSaturationLM("Hue Saturation", Range(0, 4)) = 1 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueBrightnessLM("Hue Brightness", Range(0, 2)) = 1 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_ContrastLM("Contrast", Range(0, 20)) = 1.0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_BrightnessLM("Brightness", Range(-2, 2)) = 0.0 + + //Affected By Ambient + [Effect(EffectID# CUSTOM_AMBIENT_LIGHT, GroupID# Lighting)][Toggle(_CUSTOM_AMBIENT_LIGHT_ON)]_CustomAmbientLightOn("Custom Ambient Light", Float) = 0.0 + [EffectProperty(CUSTOM_AMBIENT_LIGHT)]_CustomAmbientColor("Custom Ambient Color", Color) = (0.65, 0.65, 0.65, 1.0) + + //Cast Shadows Enabled + [Effect(EffectID# CAST_SHADOWS_ON, GroupID# Lighting, ExtraPasses# (SHADOW_CASTER))][Toggle(_CAST_SHADOWS_ON)]_CastShadowsOn("Cast Shadows", Float) = 1.0 + + //Receive Shadows + [Effect(EffectID# RECEIVE_SHADOWS, GroupID# Lighting, ExtraPasses# (SHADOW_CASTER))][Toggle(_RECEIVE_SHADOWS_ON)]_ReceiveShadows("Receive Shadows", Float) = 1.0 + [EffectProperty(RECEIVE_SHADOWS)][KeywordEnum(Classic, Stylized)] _ReceivedShadowsType("Shadow Type", Float) = 0 + [EffectProperty(ParentEffect# RECEIVE_SHADOWS, Keywords(_RECEIVEDSHADOWSTYPE_STYLIZED), AllowReset# True)] _ShadowCutoff("Cutoff", Range(0.001, 0.5)) = 0.2 + + //Scroll Texture + [Effect(EffectID# SCROLL_TEXTURE, GroupID# UVEffects)][Toggle(_SCROLL_TEXTURE_ON)]_ScrollTextureOn("Scroll Texture", Float) = 0 + [EffectProperty(SCROLL_TEXTURE)]_ScrollTextureX("Scroll X", Float) = 1.0 + [EffectProperty(SCROLL_TEXTURE)]_ScrollTextureY("Scroll Y", Float) = 1.0 + + //Screen Space UVs + [Effect(EffectID# SCREEN_SPACE_UV, GroupID# UVEffects, IncompatibleWith# TRIPLANAR_MAPPING)][Toggle(_SCREEN_SPACE_UV_ON)]_ScreenSpaceUVOn("Screen Space UV", Float) = 0.0 + [EffectProperty(SCREEN_SPACE_UV)]_ScaleWithCameraDistance("Scale with camera distance", Range(0, 1)) = 0.0 + + //Pixelate + [Effect(EffectID# PIXELATE, GroupID# UVEffects)][Toggle(_PIXELATE_ON)]_Pixelate("Pixelate", Float) = 0 + [EffectProperty(PIXELATE)]_PixelateSize("Pixelate Size", Range(4, 512)) = 32 + + //Stochastic Texture Sampling + [Effect(EffectID# STOCHASTIC_SAMPLING, GroupID# UVEffects)][Toggle(_STOCHASTIC_SAMPLING_ON)]_StochasticSampling("Stochastic Sampling", Float) = 0 + [EffectProperty(STOCHASTIC_SAMPLING)]_StochasticScale("Grid Scale", Range(0, 10)) = 3.464 + [EffectProperty(STOCHASTIC_SAMPLING)]_StochasticSkew("Grid Skew", Range(0, 3)) = 0.57735027 + + //Wave UV + [Effect(EffectID# WAVE_UV, GroupID# UVEffects)][Toggle(_WAVE_UV_ON)]_WaveUVOn("Wave UV On", Float) = 0 + [EffectProperty(WAVE_UV)]_WaveAmount("Wave Amount", Range(0, 25)) = 7 + [EffectProperty(WAVE_UV)]_WaveSpeed("Wave Speed", Range(0, 25)) = 10 + [EffectProperty(WAVE_UV)]_WaveStrength("Wave Strength", Range(0, 25)) = 7.5 + [EffectProperty(WAVE_UV)]_WaveX("Wave X Axis", Range(0, 1)) = 0 + [EffectProperty(WAVE_UV)]_WaveY("Wave Y Axis", Range(0, 1)) = 0.5 + + //AO Map + [Effect(EffectID# AOMAP, GroupID# ColorEffects)][Toggle(_AOMAP_ON)]_AOMapEnabled("AO Map", Float) = 0 + [EffectProperty(AOMAP)][NoScaleOffset]_AOMap("AO Map", 2D) = "white" {} + [EffectProperty(AOMAP)]_AOMapStrength("AO Strength", Range(0, 1)) = 1.0 + [EffectProperty(AOMAP)]_AOContrast("AO Contrast", Range(0, 1)) = 1.0 + [EffectProperty(AOMAP)]_AOColor("AO Color", Color) = (0, 0, 0, 0) + + //Highlights + [Effect(EffectID# HIGHLIGHTS, GroupID# ColorEffects)][Toggle(_HIGHLIGHTS_ON)]_Highlights("Highlights", Float) = 0 + [EffectProperty(HIGHLIGHTS)][HDR]_HighlightsColor("Highlights Color", Color) = (2, 2, 2, 1) + [EffectProperty(HIGHLIGHTS)]_HighlightsStrength("Highlights Strength", Range(0, 1)) = 1 + [EffectProperty(HIGHLIGHTS)]_HighlightCutoff("Highlight Cutoff", Range(0, 1)) = 0.5 + [EffectProperty(HIGHLIGHTS)]_HighlightSmoothness("Highlight Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(HIGHLIGHTS)][Vector3]_HighlightOffset("Highlight Offset", Vector) = (0, 0, 0, 0) + + //Rim + [Effect(EffectID# RIM_LIGHTING, GroupID# ColorEffects)][Toggle(_RIM_LIGHTING_ON)]_RimLighting("Rim or Fresnel", Float) = 0 + [EffectProperty(ParentEffect# RIM_LIGHTING, Keywords(_RIM_LIGHTING_ON), AllowReset# False)][KeywordEnum(BeforeLighting, BeforeLightingLast, AfterLighting)]_RimLightingStage("Stage", Float) = 0.0 + [EffectProperty(RIM_LIGHTING)][HDR]_RimColor("Rim Color", Color) = (1, 1, 1, 1) + [EffectProperty(RIM_LIGHTING)]_RimAttenuation("Rim Attenuation", Range(0, 1)) = 1.0 + [EffectProperty(RIM_LIGHTING)]_MinRim("Min Rim", Range(0, 1)) = 0 + [EffectProperty(RIM_LIGHTING)]_MaxRim("Max Rim", Range(0, 1)) = 1.0 + [EffectProperty(RIM_LIGHTING)][Vector3]_RimOffset("Rim Offset", Vector) = (0, 0, 0, 0) + + //Greyscale + [Effect(EffectID# GREYSCALE, GroupID# ColorEffects)][Toggle(_GREYSCALE_ON)]_Greyscale("Greyscale", Float) = 0 + [EffectProperty(GREYSCALE)][KeywordEnum(BeforeLighting, AfterLighting)] _GreyScaleStage("Stage", Float) = 0 + [EffectProperty(GREYSCALE)] _GreyscaleLuminosity("Luminosity", Range(-1, 1)) = 0 + [EffectProperty(GREYSCALE)] _GreyscaleTintColor("Greyscale Tint", Color) = (1.0, 1.0, 1.0, 1.0) + [EffectProperty(GREYSCALE)] _GreyscaleBlending("Blending", Range(0, 1)) = 1 + + //Posterize + [Effect(EffectID# POSTERIZE, GroupID# ColorEffects)][Toggle(_POSTERIZE_ON)]_Posterize("Posterize", Float) = 0 + [EffectProperty(POSTERIZE)] _PosterizeNumColors("Number of Colors", Range(0,200)) = 8 + [EffectProperty(POSTERIZE)] _PosterizeGamma("Posterize Gamma", Range(0.1,10)) = 0.75 + + //Hand Drawn + [Effect(EffectID# HAND_DRAWN, GroupID# UVEffects)][Toggle(_HAND_DRAWN_ON)]_HandDrawn("Hand Drawn", Float) = 0 + [EffectProperty(HAND_DRAWN)]_HandDrawnAmount("Hand Drawn Amount", Range(0, 50)) = 10 + [EffectProperty(HAND_DRAWN)]_HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 + + //Distortion + [Effect(EffectID# UV_DISTORTION, GroupID# UVEffects)][Toggle(_UV_DISTORTION_ON)]_UVDistortion("Distortion", Float) = 0 + [EffectProperty(UV_DISTORTION)]_DistortTex("Distortion Texture", 2D) = "white" {} + [EffectProperty(UV_DISTORTION)]_DistortAmount("Distortion Amount", Range(0,4)) = 0.3 + [EffectProperty(UV_DISTORTION)]_DistortTexXSpeed("Scroll speed X", Range(-10,10)) = 2 + [EffectProperty(UV_DISTORTION)]_DistortTexYSpeed("Scroll speed Y", Range(-10,10)) = 2 + + //Vertex Shake + [Effect(EffectID# VERTEX_SHAKE, GroupID# MeshEffects)][Toggle(_VERTEX_SHAKE_ON)] _VertexShakeOn("Vertex Shake", Float) = 0 + [EffectProperty(VERTEX_SHAKE)][Vector3] _ShakeSpeed("Speed", Vector) = (41, 49, 45, 0) + [EffectProperty(VERTEX_SHAKE)] _ShakeSpeedMult("Shake Mult", Float) = 1.0 + [EffectProperty(VERTEX_SHAKE)][Vector3] _ShakeMaxDisplacement("Shake Max Displacement", Vector) = (0.1, 0.1, 0.1, 0) + [EffectProperty(VERTEX_SHAKE)] _ShakeBlend("Shake Blend", Range(0, 1)) = 1.0 + + //Vertex Inflate + [Effect(EffectID# VERTEX_INFLATE, GroupID# MeshEffects)][Toggle(_VERTEX_INFLATE_ON)] _VertexInflate("Vertex Inflate", Float) = 0 + [EffectProperty(VERTEX_INFLATE)]_MinInflate("Min Inflate", Float) = 0.0 + [EffectProperty(VERTEX_INFLATE)]_MaxInflate("Max Inflate", Float) = 0.2 + [EffectProperty(VERTEX_INFLATE)]_InflateBlend("Inflate blend", Range(0, 1)) = 1.0 + + //Vertex Distortion + [Effect(EffectID# VERTEX_DISTORTION, GroupID# MeshEffects)][Toggle(_VERTEX_DISTORTION_ON)]_VertexDistortionOn("Vertex Distortion", Float) = 0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseTex("Noise Tex", 2D) = "white" {} + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionAmount("Distortion Amount", Range(0, 2)) = 0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseSpeedX("Scroll Speed X", Range(-10, 10)) = 4.0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseSpeedY("Scroll Speed Y", Range(-10, 10)) = 4.0 + + + //Voxelize + [Effect(EffectID# VOXELIZE, GroupID# MeshEffects)][Toggle(_VOXELIZE_ON)] _Voxelize("Voxelize", Float) = 0 + [EffectProperty(VOXELIZE)]_VoxelSize("Voxel Size", Range(0.1, 500)) = 100 + [EffectProperty(VOXELIZE)]_VoxelBlend("Blend Amount", Range(0, 1)) = 1 + + //Glitch + [Effect(EffectID# GLITCH, GroupID# MeshEffects)][Toggle(_GLITCH_ON)]_Glitch("Glitch", Float) = 0 + [EffectProperty(GLITCH)]_GlitchTiling ("Glitch Tiling", Float) = 5 + [EffectProperty(GLITCH)]_GlitchAmount ("Glitch Amount", Range(0, 1)) = 0.5 + [EffectProperty(GLITCH)]_GlitchOffset ("Glitch Offset", Vector) = (-0.5, 0, 0, 0) + [EffectProperty(GLITCH)]_GlitchSpeed ("Glitch Speed", Float) = 2.5 + [EffectProperty(GLITCH)][Toggle]_GlitchWorldSpace ("Use World Space", Float) = 1 + + //Recalculate Normals + [Effect(EffectID# RECALCULATE_NORMALS, GroupID# MeshEffects)][Toggle(_RECALCULATE_NORMALS_ON)]_RecalculateNormals("Recalculate Normals", Float) = 0 + + //Wind + [Effect(EffectID# WIND, GroupID# MeshEffects)][Toggle(_WIND_ON)]_WindOn("Wind", Float) = 0 + [EffectProperty(WIND)]_WindAttenuation("Attenuation", Range(0, 1)) = 1.0 + [EffectProperty(WIND)][Toggle(_USE_WIND_VERTICAL_MASK)]_UseVerticalMask("Use Vertical Mask?", Float) = 1.0 + [EffectProperty(ParentEffect# WIND, Keywords(_USE_WIND_VERTICAL_MASK), AllowReset# True)]_WindVerticalMaskMinY("Min Y", Float) = -1.0 + [EffectProperty(ParentEffect# WIND, Keywords(_USE_WIND_VERTICAL_MASK), AllowReset# True)]_WindVerticalMaskMaxY("Max Y", Float) = 1.0 + + //Hue Shift + [Effect(EffectID# HUE_SHIFT, GroupID# ColorEffects)][Toggle(_HUE_SHIFT_ON)] _HueShiftEnabled("Hue Shift", Float) = 0 + [EffectProperty(HUE_SHIFT)]_HueShift("Hue Shift", Range(0, 360)) = 0 + [EffectProperty(HUE_SHIFT)]_HueSaturation("Saturation", Range(0, 4)) = 1 + [EffectProperty(HUE_SHIFT)]_HueBrightness("Brightness", Range(0, 2)) = 1 + + //Emission + [Effect(EffectID# EMISSION, GroupID# ColorEffects)][Toggle(_EMISSION_ON)] _EmissionEnabled("Emission", Float) = 0 + [EffectProperty(EMISSION)]_EmissionSelfGlow("Emission Self Glow", Range(0, 20)) = 1 + [EffectProperty(EMISSION)][HDR]_EmissionColor("Emission Color", Color) = (1, 1, 1, 1) + [EffectProperty(EMISSION)]_EmissionMap("Emission Map", 2D) = "white" {} + + //Hologram + [Effect(EffectID# HOLOGRAM, GroupID# ColorEffects)][Toggle(_HOLOGRAM_ON)] _Hologram("Hologram", Float) = 0 + [EffectProperty(HOLOGRAM)][HDR]_HologramColor("Hologram Color", Color) = (1.25,2.8,6.8,1) + [EffectProperty(HOLOGRAM)]_HologramLineDirection("Line Direction", Vector) = (0,1,0,0) + [EffectProperty(HOLOGRAM)]_HologramBaseAlpha("Hologram Base Alpha", Range(0, 1)) = 0.1 + + [EffectProperty(HOLOGRAM)]_HologramScrollSpeed("Hologram Scroll Speed", Float) = 2 + [EffectProperty(HOLOGRAM)]_HologramFrequency("Hologram Frequency", Float) = 20 + [EffectProperty(HOLOGRAM)]_HologramAlpha("Hologram Alpha", Range(0, 1)) = 1 + + [EffectProperty(HOLOGRAM)]_HologramAccentSpeed("Hologram Accent Speed", Float) = 1 + [EffectProperty(HOLOGRAM)]_HologramAccentFrequency("Hologram Accent Frequency", Float) = 2 + [EffectProperty(HOLOGRAM)]_HologramAccentAlpha("Hologram Accent Alpha", Range(0, 1)) = 0.5 + + [EffectProperty(HOLOGRAM)]_HologramLineCenter("Hologram Line Center", Range(0, 1)) = 0.5 + [EffectProperty(HOLOGRAM)]_HologramLineSpacing("Hologram Line Spacing", Range(0.001, 5)) = 2.0 + [EffectProperty(HOLOGRAM)]_HologramLineSmoothness("Hologram Line Smoothness", Range(0.01, 5)) = 2.0 + + //Matcap + [Effect(EffectID# MATCAP, GroupID# ColorEffects)][Toggle(_MATCAP_ON)]_Matcap("Matcap", Float) = 0 + [EffectProperty(MATCAP)][KeywordEnum(Multiply, Replace)]_MatcapBlendMode("Blend Mode", Float) = 0 + [EffectProperty(MATCAP)][NoScaleOffset]_MatcapTex("Matcap Tex", 2D) = "white" {} + [EffectProperty(MATCAP)]_MatcapIntensity("Matcap Intensity", Range(0, 10)) = 1.0 + [EffectProperty(MATCAP)]_MatcapBlend("Matcap Blend", Range(0, 1)) = 1.0 + + //Hit + [Effect(EffectID# HIT, GroupID# ColorEffects)][Toggle(_HIT_ON)] _Hit("Hit", Float) = 0 + [EffectProperty(HIT)]_HitColor("Hit Color", Color) = (1, 1, 1, 1) + [EffectProperty(HIT)]_HitGlow("Hit Glow", Range(0, 100)) = 5 + [EffectProperty(HIT)]_HitBlend("Hit Blend", Range(0, 1)) = 1.0 + + //Contrast and Brightness + [Effect(EffectID# CONTRAST_BRIGHTNESS, GroupID# ColorEffects)][Toggle(_CONTRAST_BRIGHTNESS_ON)]_ContrastBrightnessOn("Contrast and Brightness", Float) = 0 + [EffectProperty(CONTRAST_BRIGHTNESS)]_Contrast("Contrast", Range(0, 10)) = 1.0 + [EffectProperty(CONTRAST_BRIGHTNESS)]_Brightness("Brightness", Range(-1, 1)) = 0.0 + + //Height Gradient + [Effect(EffectID# HEIGHT_GRADIENT, GroupID# ColorEffects)][Toggle(_HEIGHT_GRADIENT_ON)]_HeightGradientOn("Height Gradient", Float) = 0 + [EffectProperty(HEIGHT_GRADIENT)][KeywordEnum(Local, World)]_HeightGradientPositionSpace("Position Space", Float) = 0 + [EffectProperty(HEIGHT_GRADIENT)]_MinGradientHeight("Min Height", Float) = 0.0 + [EffectProperty(HEIGHT_GRADIENT)]_MaxGradientHeight("Max Height", Float) = 0.75 + [EffectProperty(HEIGHT_GRADIENT)][HDR]_GradientHeightColor01("Gradient Color 01", Color) = (0.2, 0.2, 0.2, 1) + [EffectProperty(HEIGHT_GRADIENT)][HDR]_GradientHeightColor02("Gradient Color 02", Color) = (1, 1, 1, 1) + + //Intersection Glow + [Effect(EffectID# INTERSECTION_GLOW, GroupID# ColorEffects)][Toggle(_INTERSECTION_GLOW_ON)]_IntersectionGlowOn("Intersection Glow", Float) = 0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowDist("Depth Distance", Range(0.01, 10)) = 0.2 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowPower("Depth Power", Float) = 25.0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowColor("Depth Glow Color", Color) = (1.0, 0.987, 0.6, 1.0) + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowColorIntensity("Color Intensity", Float) = 25.0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowGlobalIntensity("Global Intensity", Float) = 2.0 + + //Albedo from Vertex Color + [Effect(EffectID# ALBEDO_VERTEX_COLOR, GroupID# ColorEffects)][Toggle(_ALBEDO_VERTEX_COLOR_ON)]_AlbedoVertexColorOn("Albedo From Vertex Color", Float) = 0 + [EffectProperty(ALBEDO_VERTEX_COLOR)][KeywordEnum(Multiply, Replace)]_AlbedoVertexColorMode("Mode", Float) = 1 + [EffectProperty(ALBEDO_VERTEX_COLOR)]_VertexColorBlending("Blending", Range(0, 1)) = 1.0 + + //Triplanar Mapping + [Effect(EffectID# TRIPLANAR_MAPPING, GroupID# ColorEffects, IncompatibleWith# SCREEN_SPACE_UV, CustomDrawer# TRIPLANAR_EFFECT_DRAWER)][Toggle(_TRIPLANAR_MAPPING_ON)]_TriplanarMappingOn("Triplanar Mapping", Float) = 0 + [EffectProperty(TRIPLANAR_MAPPING)][KeywordEnum(Local, World)] _TriplanarNormalSpace("UV Space", Float) = 1.0 + [EffectProperty(TRIPLANAR_MAPPING)]_TriplanarTopTex("Top Texture", 2D) = "white" {} + [NoScaleOffset][EffectProperty(TRIPLANAR_MAPPING)]_TriplanarTopNormalMap("Top Normal Map", 2D) = "bump" {} + [EffectProperty(TRIPLANAR_MAPPING)]_TopNormalStrength("Top Normal Map Strength", Range(0.0, 10.0)) = 1.0 + [EffectProperty(TRIPLANAR_MAPPING)]_FaceDownCutoff("Face Down Cutoff", Range(-1, 1)) = 0.25 + [EffectProperty(TRIPLANAR_MAPPING)]_TriplanarSharpness("Sharpness", Range(1, 200)) = 15.0 + [EffectProperty(TRIPLANAR_MAPPING)][Toggle(_TRIPLANAR_NOISE_TRANSITION_ON)]_TriplanarNoiseTransitionOn("Noise Transition", Float) = 0 + [EffectProperty(ParentEffect# TRIPLANAR_MAPPING, Keywords(_TRIPLANAR_NOISE_TRANSITION_ON), AllowReset# True)] _TriplanarNoiseTex("Noise Tex", 2D) = "white" {} + [EffectProperty(ParentEffect# TRIPLANAR_MAPPING, Keywords(_TRIPLANAR_NOISE_TRANSITION_ON), AllowReset# True)] _TriplanarTransitionPower("Transition Power", Range(0, 1.0)) = 0.75 + + //Texture Blending + [Effect(EffectID# TEXTURE_BLENDING, GroupID# ColorEffects, CustomDrawer# TEXTURE_BLENDING_EFFECT_DRAWER)][Toggle(_TEXTURE_BLENDING_ON)]_TextureBlending ("Texture Blending", Float) = 0 + [EffectProperty(TEXTURE_BLENDING)][KeywordEnum(VertexColor, Texture)]_TextureBlendingSource("Source", Float) = 0 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE), AllowReset# True)]_TexBlendingMask("Texture Blending Mask", 2D) = "white" {} + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffG("Cutoff (G)", Range(0, 1)) = 0.1 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessG("Smoothness (G)", Range(0, 1)) = 0.4 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffB("Cutoff (B)", Range(0, 1)) = 0.1 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessB("Smoothness (B)", Range(0, 1)) = 0.4 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffWhite("Cutoff (White)", Range(0, 1)) = 0.15 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessWhite("Smoothness (White)", Range(0, 1)) = 0.4 + [EffectProperty(TEXTURE_BLENDING)][KeywordEnum(RGB, BlackAndWhite)]_TextureBlendingMode("Blending Mode", Float) = 0 + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureG("Blending Texture (G)", 2D) = "white" {} + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureB("Blending Texture (B)", 2D) = "white" {} + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureWhite("Blending Texture (White)", 2D) = "white" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapG("Blending Normal Map (G)", 2D) = "bump" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapB("Blending Normal Map (B)", 2D) = "bump" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapWhite("Blending Normal Map (White)", 2D) = "bump" {} + + //Depth Coloring + [Effect(EffectID# DEPTH_COLORING, GroupID# ColorEffects)][Toggle(_DEPTH_COLORING_ON)]_DepthColoringOn("Depth Coloring", Float) = 0 + + //Sub surface scattering + [Effect(EffectID# SUBSURFACE_SCATTERING, GroupID# ColorEffects)][Toggle(_SUBSURFACE_SCATTERING_ON)]_SubsurfaceScattering("Fake Subsurface Scattering", Float) = 0.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_NormalInfluence("Normal Influence", Range(0, 2.5)) = 0.5 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSPower("SSS Power", Range(0.01, 20)) = 1.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSFrontPower("SSS Front Power", Range(0.2, 20)) = 3.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSFrontAtten("SSS Front Atten", Range(0, 1)) = 0.3 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSAtten("SSS General Atten", Range(0, 1)) = 1.0 + [EffectProperty(SUBSURFACE_SCATTERING)][HDR]_SSSColor("SSS Color", Color) = (1.0, 1.0, 1.0, 1.0) + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSMap("SSS Map", 2D) = "white" {} + + //Alpha Cutoff + [Effect(EffectID# ALPHA_CUTOFF, GroupID# AlphaEffects)][Toggle(_ALPHA_CUTOFF_ON)]_AlphaCutoffOn("Alpha Cutoff", Float) = 1.0 + [EffectProperty(ALPHA_CUTOFF)]_AlphaCutoffValue("Cutoff Value", Range(0, 1)) = 0.25 + + //Fade + [Effect(EffectID# FADE, GroupID# AlphaEffects)][Toggle(_FADE_ON)]_FadeOn("Fade", Float) = 0 + [EffectProperty(FADE)]_FadeTex("Fade Tex", 2D) = "white" {} + [EffectProperty(FADE)][KeywordEnum(UV1, UV2, WORLD_SPACE)]_FadeUVSet("UV Set", Float) = 0 + [EffectProperty(FADE)]_FadeAmount("Fade Amount", Range(0, 1)) = 0.0 + [EffectProperty(FADE)]_FadePower("Fade Power", Range(0.25, 4.0)) = 1.0 + [EffectProperty(FADE)]_FadeTransition("Fade Transition", Range(0, 0.4)) = 0.2 + [EffectProperty(FADE)][Toggle(_FADE_BURN_ON)]_FadeBurnOn("Use Fade Burn Color?", Float) = 0.0 + [EffectProperty(ParentEffect# FADE, Keywords(_FADE_BURN_ON), AllowReset# True)][HDR]_FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) + [EffectProperty(ParentEffect# FADE, Keywords(_FADE_BURN_ON), AllowReset# True)]_FadeBurnWidth("Fade Burn Width", Range(0, 0.2)) = 0.01 + + //Intersection Fade + [Effect(EffectID# INTERSECTION_FADE, GroupID# AlphaEffects)][Toggle(_INTERSECTION_FADE_ON)]_IntersectionFadeOn("Intersection Fade", Float) = 0.0 + [EffectProperty(INTERSECTION_FADE)]_IntersectionFadeFactor("Intersection Fade Factor", Range(0.1, 3.0)) = 1.0 + + //Alpha Round + [Effect(EffectID# ALPHA_ROUND, GroupID# AlphaEffects)][Toggle(_ALPHA_ROUND_ON)]_AlphaRoundOn("Alpha Round", Float) = 0 + + //Fade By Cam Distance + [Effect(EffectID# FADE_BY_CAM_DISTANCE, GroupID# AlphaEffects)][Toggle(_FADE_BY_CAM_DISTANCE_ON)]_FadeByCamDistanceOn("Fade By Cam Distance", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)][Toggle(_FADE_BY_CAM_DISTANCE_NEAR_FADE)]_NearFade("Near Fade", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)]_MinDistanceToFade("Min Distance", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)]_MaxDistanceToFade("Max Distance", Float) = 100 + + //Dither + [Effect(EffectID# DITHER, GroupID# AlphaEffects)][Toggle(_DITHER_ON)]_DitherOn("Dither", Float) = 0 + [EffectProperty(DITHER)]_DitherScale("Scale", Range(0.01, 2)) = 1 + + // + [Effect(EffectID# OUTLINETYPE, GroupID# OtherEffects, ExtraPasses# (OUTLINE))][KeywordEnum(None, Simple, Constant, FadeWithDistance)]_OutlineType("Outline Type", Float) = 0 + + // + [PerRendererData]_TimingSeed("Timing Seed", Float) = 0 + + + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)][HDR]_OutlineColor("Outline Color", Color) = (0, 0, 0, 1) + [EffectProperty(OUTLINETYPE, CONSTANT)]_MaxCameraDistance("Max Camera Distance", Float) = 1000 + [EffectProperty(OUTLINETYPE, FADEWITHDISTANCE)]_MaxFadeDistance("Max Fade Distance", Float) = 250 + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)]_OutlineThickness("Outline Thickness", Float) = 1 + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)][Enum(Basic, 8, Clean, 6)]_OutlineMode("Outline Mode", Float) = 8 + [IntRange]_StencilRef("Stencil Reference Value", Range(1, 255)) = 1 + /**/ + } + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "12.0" + } + + /**/ + Pass + { + Name "AllIn13D_MainPass_URP" + Tags + { + "RenderType" = "Opaque" + "RenderPipeline" = "UniversalPipeline" + } + + Blend [_BlendSrc] [_BlendDst] + Cull [_CullingMode] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + ColorMask [_ColorMask] + + /**/ + + HLSLPROGRAM + #define URP_PASS + #define ALLIN1_FORWARD_PASS + + #pragma vertex BasicVertex + #pragma fragment BasicFragment + + + #if UNITY_VERSION >= 60000000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #endif + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #if defined(LOD_FADE_CROSSFADE) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + #endif + + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_BasePass.hlsl" + + ENDHLSL + } + /**/ + + /**/ + + Pass + { + Name "AllIn13D_ShadowCaster_URP" + Tags { "LightMode"="ShadowCaster" } + + ZWrite On + ZTest LEqual + ColorMask 0 + Cull [_CullingMode] + + HLSLPROGRAM + #define URP_PASS + #define SHADOW_CASTER_PASS + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + #pragma vertex BasicVertexShadowCaster + #pragma fragment BasicFragmentShadowCaster + + + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #if defined(LOD_FADE_CROSSFADE) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + #endif + + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl" + + ENDHLSL + } + /**/ + + /**/ + Pass + { + Name "DepthOnly" + Tags + { + "LightMode" = "DepthOnly" + } + + // ------------------------------------- + // Render State Commands + ZWrite On + ColorMask R + Cull[_CullingMode] + + HLSLPROGRAM + #define ALLIN1_DEPTH_ONLY_PASS + + // ------------------------------------- + // Shader Stages + #pragma vertex DepthOnlyVertex + #pragma fragment DepthOnlyFragment + + #define URP_PASS + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + // ------------------------------------- + // Includes + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl" + ENDHLSL + } + /**/ + + /**/ + Pass + { + Name "DepthNormals" + Tags + { + "LightMode" = "DepthNormals" + } + + ZWrite On + Cull[_CullingMode] + + HLSLPROGRAM + #define ALLIN1_DEPTH_NORMALS_PASS + + // Shader Stages + #pragma vertex DepthNormalsVertex + #pragma fragment DepthNormalsFragment + + #define URP_PASS + + #if UNITY_VERSION >= 60000000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #endif + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + //Includes + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl" + + ENDHLSL + } + /**/ + + + /**/ + Pass + { + Name "Meta" + Tags{ "LightMode" = "Meta" } + + Cull Off + + HLSLPROGRAM + #pragma exclude_renderers gles gles3 glcore + #define URP_PASS + + #pragma vertex AllIn1VertexMeta + #pragma fragment AllIn1FragmentMeta + #pragma shader_feature EDITOR_VISUALIZATION + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl" + + ENDHLSL + } + /**/ + } + + SubShader + { + /**/ + Pass + { + Name "AllIn13D_Forward_BIRP" + Tags { "LightMode" = "ForwardBase" } + + + /**/ + + + Blend [_BlendSrc] [_BlendDst] + Cull [_CullingMode] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + ColorMask [_ColorMask] + + HLSLPROGRAM + #pragma target 3.0 + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #define BIRP_PASS + #define BUILTIN_MAIN_PASS + + #pragma vertex BasicVertex + #pragma fragment BasicFragment + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_BasePass.hlsl" + + ENDHLSL + } + /**/ + + /**/ + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd"} + + Blend One One + ZWrite Off + ZTest LEqual + Cull [_CullingMode] + + HLSLPROGRAM + #pragma target 3.0 + + #define BIRP_PASS + #define FORWARD_ADD_PASS + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + + #pragma vertex BasicVertex + #pragma fragment BasicFragmentAdd + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLightAddPass.hlsl" + + ENDHLSL + } + /**/ + + /**/ + Pass + { + Name "AllIn13D_ShadowCaster" + Tags { "LightMode"="ShadowCaster" } + + ZWrite On + ZTest LEqual + ColorMask 0 + Cull[_CullingMode] + + HLSLPROGRAM + #pragma target 3.0 + + #define BIRP_PASS + #define SHADOW_CASTER_PASS + + #pragma vertex BasicVertexShadowCaster + #pragma fragment BasicFragmentShadowCaster + + #pragma multi_compile_instancing + #pragma multi_compile_shadowcaster + #pragma multi_compile _ DOTS_INSTANCING_ON + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl" + + ENDHLSL + } + /**/ + } + + /**/ + CustomEditor "AllIn13DShader.AllIn13DShaderMaterialInspector" + /**/ +} diff --git a/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader.shader.meta b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader.shader.meta new file mode 100644 index 0000000..b688437 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader.shader.meta @@ -0,0 +1,47 @@ +fileFormatVersion: 2 +guid: 0dde7f0097aeb2541aea684ca0ad0e3c +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _ColorRampTex: {fileID: 2800000, guid: 99b6592afee2790429156fef1dc9ba44, type: 3} + - _ToonRamp: {fileID: 2800000, guid: 339398f75cfa2714d93579662d08ec9a, type: 3} + - _MetallicMap: {instanceID: 0} + - _SpecularMap: {instanceID: 0} + - _NormalMap: {fileID: 2800000, guid: 120df76dc2d17ed4cb2d4b8b08292ed9, type: 3} + - _AOMap: {instanceID: 0} + - _DistortTex: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + - _VertexDistortionNoiseTex: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, + type: 3} + - _EmissionMap: {instanceID: 0} + - _MatcapTex: {fileID: 2800000, guid: cf3a2315564d4de4eb8601b697dea358, type: 3} + - _TriplanarTopTex: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, type: 3} + - _TriplanarTopNormalMap: {fileID: 2800000, guid: 8175cba73bf87af41aeba7bbd2f3c4cd, + type: 3} + - _TriplanarNoiseTex: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, + type: 3} + - _TexBlendingMask: {fileID: 2800000, guid: 5a775794f8704ba4385b9c92cf9f1224, type: 3} + - _BlendingTextureG: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, type: 3} + - _BlendingTextureB: {fileID: 2800000, guid: f39690d17007ab242928cd91e5a530a6, type: 3} + - _BlendingTextureWhite: {fileID: 2800000, guid: 2af6ba1567607124eb61349fa044375b, + type: 3} + - _BlendingNormalMapG: {fileID: 2800000, guid: 8175cba73bf87af41aeba7bbd2f3c4cd, + type: 3} + - _BlendingNormalMapB: {fileID: 2800000, guid: 6246e3fe4a63c1f4f9acec9623576fc7, + type: 3} + - _BlendingNormalMapWhite: {fileID: 2800000, guid: 8175cba73bf87af41aeba7bbd2f3c4cd, + type: 3} + - _SSSMap: {instanceID: 0} + - _FadeTex: {fileID: 2800000, guid: fcb69fdadf254834880fe3c443965278, type: 3} + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader.shader + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline.shader b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline.shader new file mode 100644 index 0000000..c855974 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline.shader @@ -0,0 +1,816 @@ +Shader "AllIn13DShader/AllIn13DShaderOutline" +{ + Properties + { + _RenderPreset("Render Preset", Float) = 1 + [AdvancedProperty]_AdvancedConfigurationEnabled("Show Advanced Configuration", Float) = 0 + [Enum(UnityEngine.Rendering.BlendMode)]_BlendSrc ("Blend mode Source", Float) = 1 + [Enum(UnityEngine.Rendering.BlendMode)]_BlendDst ("Blend mode Destination", Float) = 0 + [AdvancedProperty][Enum(UnityEngine.Rendering.CullMode)]_CullingMode("Culling Mode", Float) = 2 + [AdvancedProperty][Enum(Off, 0, On, 1)]_ZWrite("Depth Write", float) = 1.0 + [AdvancedProperty][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestMode("Z Test Mode", float) = 4 + [AdvancedProperty][Enum(UnityEngine.Rendering.ColorWriteMask)]_ColorMask("Color Write Mask", float) = 15 + [AdvancedProperty][Toggle(_FOG_ON)] _FogOn("Fog On", Float) = 0 + [AdvancedProperty][Toggle(_SPHERIZE_NORMALS_ON)]_SpherizeNormals("Spherize Normals", Float) = 0.0 + [AdvancedProperty][Toggle(_USE_CUSTOM_TIME)] _UseCustomTime("Use Custom Time", Float) = 0 + + [SingleProperty]_MainTex ("Main Texture", 2D) = "white" {} + [SingleProperty]_Color("Color", Color) = (1, 1, 1, 1) + [SingleProperty]_GeneralAlpha("General Alpha", Range(0, 1)) = 1.0 + + //Color Ramp + [Effect(EffectID# COLOR_RAMP, GroupID# ColorEffects, CustomDrawer# COLOR_RAMP_EFFECT_DRAWER)][Toggle(_COLOR_RAMP_ON)]_ColorRampOn("Color Ramp", Float) = 0 + [EffectProperty(ParentEffect# COLOR_RAMP, Keywords(_COLOR_RAMP_ON), AllowReset# False)][KeywordEnum(BeforeLighting, AfterLighting)]_ColorRampLightingStage("Stage", Float) = 0.0 + [EffectProperty(COLOR_RAMP)][AllIn13DShaderGradientDrawer]_ColorRampTex("Color Ramp Tex", 2D) = "white" {} + [EffectProperty(COLOR_RAMP)]_ColorRampLuminosity("Color Ramp Luminosity", Range(0, 1)) = 0 + [EffectProperty(COLOR_RAMP)]_ColorRampBlend("Color Ramp Blend", Range(0, 1)) = 1 + [EffectProperty(COLOR_RAMP)]_ColorRampTiling("Tiling", Range(0.01, 10)) = 1.0 + [EffectProperty(COLOR_RAMP)]_ColorRampScrollSpeed("Scroll Speed", Float) = 0.0 + + //Lighting + [Effect(EffectID# LIGHTMODEL, GroupID# Lighting, ExtraPasses# (FORWARD_ADD))][KeywordEnum(None, Classic, Toon, ToonRamp, HalfLambert, FakeGI, FastLighting)] _LightModel ("Light Model", Float) = 1 + [EffectProperty(LIGHTMODEL, TOON)]_ToonCutoff("Toon Cutoff", Range(0, 1)) = 0.5 + [EffectProperty(LIGHTMODEL, TOON)]_ToonSmoothness("Toon Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(LIGHTMODEL, TOONRAMP)][AllIn13DShaderGradientDrawer]_ToonRamp("Toon Ramp", 2D) = "white" {} + [EffectProperty(LIGHTMODEL, HALFLAMBERT)]_HalfLambertWrap("Half Lambert", Range(0, 1)) = 1 + [EffectProperty(LIGHTMODEL, FAKEGI)]_HardnessFakeGI("Fake GI Hardness", Range(0, 1)) = 0.75 + + //Shading Model + [Effect(EffectID# SHADINGMODEL, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(Basic, PBR)] _ShadingModel("Shading Model", Float) = 0 + [EffectProperty(SHADINGMODEL, PBR)]_Metallic("Metallic", Range(0, 1)) = 0 + [EffectProperty(SHADINGMODEL, PBR)]_Smoothness("Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(ParentEffect# SHADINGMODEL, Keywords(_SHADINGMODEL_PBR), AllowReset# True)][Toggle(_METALLIC_MAP_ON)]_MetallicMapOn("Use Metallic(R) / Smoothness(A) Map?", Float) = 0.0 + [EffectProperty(ParentEffect# SHADINGMODEL, KeywordsOp# AND, Keywords(_SHADINGMODEL_PBR, _METALLIC_MAP_ON), AllowReset# True)]_MetallicMap("Metallic Map", 2D) = "white" {} + + //Specular + [Effect(EffectID# SPECULARMODEL, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(None, Classic, Toon, Anisotropic, AnisotropicToon)]_SpecularModel ("Specular Model", Float) = 0 + [EffectProperty(SPECULARMODEL, CLASSIC, TOON, ANISOTROPIC, ANISOTROPICTOON)]_SpecularAtten("Specular Attenuation", Range(0, 1)) = 0.5 + [EffectProperty(ParentEffect# SPECULARMODEL, IncompatibleWithKws(_SHADINGMODEL_PBR), Keywords(_SPECULARMODEL_CLASSIC, _SPECULARMODEL_TOON), AllowReset# True)]_Shininess("Shininess", Range(0.01, 25)) = 16.0 + [EffectProperty(ParentEffect# SPECULARMODEL, IncompatibleWithKws(_SHADINGMODEL_PBR), Keywords(_SPECULARMODEL_ANISOTROPIC, _SPECULARMODEL_ANISOTROPICTOON), AllowReset# True)]_AnisoShininess("Aniso Shininess", Range(0, 1)) = 0.85 + [EffectProperty(SPECULARMODEL, TOON, ANISOTROPICTOON)]_SpecularToonCutoff("Specular Toon Cutoff", Range(0, 1)) = 0.35 + [EffectProperty(SPECULARMODEL, TOON, ANISOTROPICTOON)]_SpecularToonSmoothness("Specular Toon Smoothness", Range(0, 1)) = 0.0 + [EffectProperty(SPECULARMODEL, CLASSIC, TOON, ANISOTROPIC, ANISOTROPICTOON)]_SpecularMap("Specular Map", 2D) = "white" {} + [EffectProperty(SPECULARMODEL, ANISOTROPIC, ANISOTROPICTOON)]_Anisotropy("Anisotropy", Range(-1, 1)) = 0.45 + + //Reflections + [Effect(EffectID# REFLECTIONS, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(None, Classic, Toon)]_Reflections("Reflections", Float) = 0.0 + [EffectProperty(REFLECTIONS, TOON)]_ToonFactor("Toon Factor", Range(0, 1)) = 0 + [EffectProperty(REFLECTIONS, CLASSIC, TOON)]_ReflectionsAtten("Attenuation", Range(0, 1)) = 0.5 + + //Normal Map + [Effect(EffectID# NORMAL_MAP, GroupID# Lighting, DependentOn# LIGHTMODEL, CustomDrawer# NORMAL_MAP_EFFECT_DRAWER)][Toggle(_NORMAL_MAP_ON)]_NormalMapEnabled("Normal Map", Float) = 0 + [NoScaleOffset][EffectProperty(NORMAL_MAP)]_NormalMap("Normal Map", 2D) = "bump" {} + [EffectProperty(NORMAL_MAP)]_NormalStrength("Normal Strength", Range(0.0, 10.0)) = 1.0 + + //Flat Normals + [Effect(EffectID# FLAT_NORMALS, GroupID# Lighting, DependentOn# LIGHTMODEL)][Toggle(_FLAT_NORMALS_ON)]_FlatNormalsEnabled("Flat Normals", Float) = 0 + [EffectProperty(FLAT_NORMALS)]_FlatNormalsBlend("Blending", Range(0, 1)) = 1.0 + + //Custom Shadow Color + [Effect(EffectID# CUSTOM_SHADOW_COLOR, GroupID# Lighting)][Toggle(_CUSTOM_SHADOW_COLOR_ON)]_CustomShadowColorOn("Custom Shadow Color", Float) = 0 + + //Lightmaps + [Effect(EffectID# AFFECTED_BY_LIGHTMAPS, GroupID# Lighting)][Toggle(_AFFECTED_BY_LIGHTMAPS_ON)]_AffectedByLightmaps("Affected by lightmaps", Float) = 0 + [EffectProperty(AFFECTED_BY_LIGHTMAPS)][Toggle(_LIGHTMAP_COLOR_CORRECTION_ON)]_LightmapColorCorrection("Lightmap Color Correction?", Float) = 0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueShiftLM("Hue Shift", Range(0, 360)) = 0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueSaturationLM("Hue Saturation", Range(0, 4)) = 1 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueBrightnessLM("Hue Brightness", Range(0, 2)) = 1 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_ContrastLM("Contrast", Range(0, 20)) = 1.0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_BrightnessLM("Brightness", Range(-2, 2)) = 0.0 + + //Affected By Ambient + [Effect(EffectID# CUSTOM_AMBIENT_LIGHT, GroupID# Lighting)][Toggle(_CUSTOM_AMBIENT_LIGHT_ON)]_CustomAmbientLightOn("Custom Ambient Light", Float) = 0.0 + [EffectProperty(CUSTOM_AMBIENT_LIGHT)]_CustomAmbientColor("Custom Ambient Color", Color) = (0.65, 0.65, 0.65, 1.0) + + //Cast Shadows Enabled + [Effect(EffectID# CAST_SHADOWS_ON, GroupID# Lighting, ExtraPasses# (SHADOW_CASTER))][Toggle(_CAST_SHADOWS_ON)]_CastShadowsOn("Cast Shadows", Float) = 1.0 + + //Receive Shadows + [Effect(EffectID# RECEIVE_SHADOWS, GroupID# Lighting, ExtraPasses# (SHADOW_CASTER))][Toggle(_RECEIVE_SHADOWS_ON)]_ReceiveShadows("Receive Shadows", Float) = 1.0 + [EffectProperty(RECEIVE_SHADOWS)][KeywordEnum(Classic, Stylized)] _ReceivedShadowsType("Shadow Type", Float) = 0 + [EffectProperty(ParentEffect# RECEIVE_SHADOWS, Keywords(_RECEIVEDSHADOWSTYPE_STYLIZED), AllowReset# True)] _ShadowCutoff("Cutoff", Range(0.001, 0.5)) = 0.2 + + //Scroll Texture + [Effect(EffectID# SCROLL_TEXTURE, GroupID# UVEffects)][Toggle(_SCROLL_TEXTURE_ON)]_ScrollTextureOn("Scroll Texture", Float) = 0 + [EffectProperty(SCROLL_TEXTURE)]_ScrollTextureX("Scroll X", Float) = 1.0 + [EffectProperty(SCROLL_TEXTURE)]_ScrollTextureY("Scroll Y", Float) = 1.0 + + //Screen Space UVs + [Effect(EffectID# SCREEN_SPACE_UV, GroupID# UVEffects, IncompatibleWith# TRIPLANAR_MAPPING)][Toggle(_SCREEN_SPACE_UV_ON)]_ScreenSpaceUVOn("Screen Space UV", Float) = 0.0 + [EffectProperty(SCREEN_SPACE_UV)]_ScaleWithCameraDistance("Scale with camera distance", Range(0, 1)) = 0.0 + + //Pixelate + [Effect(EffectID# PIXELATE, GroupID# UVEffects)][Toggle(_PIXELATE_ON)]_Pixelate("Pixelate", Float) = 0 + [EffectProperty(PIXELATE)]_PixelateSize("Pixelate Size", Range(4, 512)) = 32 + + //Stochastic Texture Sampling + [Effect(EffectID# STOCHASTIC_SAMPLING, GroupID# UVEffects)][Toggle(_STOCHASTIC_SAMPLING_ON)]_StochasticSampling("Stochastic Sampling", Float) = 0 + [EffectProperty(STOCHASTIC_SAMPLING)]_StochasticScale("Grid Scale", Range(0, 10)) = 3.464 + [EffectProperty(STOCHASTIC_SAMPLING)]_StochasticSkew("Grid Skew", Range(0, 3)) = 0.57735027 + + //Wave UV + [Effect(EffectID# WAVE_UV, GroupID# UVEffects)][Toggle(_WAVE_UV_ON)]_WaveUVOn("Wave UV On", Float) = 0 + [EffectProperty(WAVE_UV)]_WaveAmount("Wave Amount", Range(0, 25)) = 7 + [EffectProperty(WAVE_UV)]_WaveSpeed("Wave Speed", Range(0, 25)) = 10 + [EffectProperty(WAVE_UV)]_WaveStrength("Wave Strength", Range(0, 25)) = 7.5 + [EffectProperty(WAVE_UV)]_WaveX("Wave X Axis", Range(0, 1)) = 0 + [EffectProperty(WAVE_UV)]_WaveY("Wave Y Axis", Range(0, 1)) = 0.5 + + //AO Map + [Effect(EffectID# AOMAP, GroupID# ColorEffects)][Toggle(_AOMAP_ON)]_AOMapEnabled("AO Map", Float) = 0 + [EffectProperty(AOMAP)][NoScaleOffset]_AOMap("AO Map", 2D) = "white" {} + [EffectProperty(AOMAP)]_AOMapStrength("AO Strength", Range(0, 1)) = 1.0 + [EffectProperty(AOMAP)]_AOContrast("AO Contrast", Range(0, 1)) = 1.0 + [EffectProperty(AOMAP)]_AOColor("AO Color", Color) = (0, 0, 0, 0) + + //Highlights + [Effect(EffectID# HIGHLIGHTS, GroupID# ColorEffects)][Toggle(_HIGHLIGHTS_ON)]_Highlights("Highlights", Float) = 0 + [EffectProperty(HIGHLIGHTS)][HDR]_HighlightsColor("Highlights Color", Color) = (2, 2, 2, 1) + [EffectProperty(HIGHLIGHTS)]_HighlightsStrength("Highlights Strength", Range(0, 1)) = 1 + [EffectProperty(HIGHLIGHTS)]_HighlightCutoff("Highlight Cutoff", Range(0, 1)) = 0.5 + [EffectProperty(HIGHLIGHTS)]_HighlightSmoothness("Highlight Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(HIGHLIGHTS)][Vector3]_HighlightOffset("Highlight Offset", Vector) = (0, 0, 0, 0) + + //Rim + [Effect(EffectID# RIM_LIGHTING, GroupID# ColorEffects)][Toggle(_RIM_LIGHTING_ON)]_RimLighting("Rim or Fresnel", Float) = 0 + [EffectProperty(ParentEffect# RIM_LIGHTING, Keywords(_RIM_LIGHTING_ON), AllowReset# False)][KeywordEnum(BeforeLighting, BeforeLightingLast, AfterLighting)]_RimLightingStage("Stage", Float) = 0.0 + [EffectProperty(RIM_LIGHTING)][HDR]_RimColor("Rim Color", Color) = (1, 1, 1, 1) + [EffectProperty(RIM_LIGHTING)]_RimAttenuation("Rim Attenuation", Range(0, 1)) = 1.0 + [EffectProperty(RIM_LIGHTING)]_MinRim("Min Rim", Range(0, 1)) = 0 + [EffectProperty(RIM_LIGHTING)]_MaxRim("Max Rim", Range(0, 1)) = 1.0 + [EffectProperty(RIM_LIGHTING)][Vector3]_RimOffset("Rim Offset", Vector) = (0, 0, 0, 0) + + //Greyscale + [Effect(EffectID# GREYSCALE, GroupID# ColorEffects)][Toggle(_GREYSCALE_ON)]_Greyscale("Greyscale", Float) = 0 + [EffectProperty(GREYSCALE)][KeywordEnum(BeforeLighting, AfterLighting)] _GreyScaleStage("Stage", Float) = 0 + [EffectProperty(GREYSCALE)] _GreyscaleLuminosity("Luminosity", Range(-1, 1)) = 0 + [EffectProperty(GREYSCALE)] _GreyscaleTintColor("Greyscale Tint", Color) = (1.0, 1.0, 1.0, 1.0) + [EffectProperty(GREYSCALE)] _GreyscaleBlending("Blending", Range(0, 1)) = 1 + + //Posterize + [Effect(EffectID# POSTERIZE, GroupID# ColorEffects)][Toggle(_POSTERIZE_ON)]_Posterize("Posterize", Float) = 0 + [EffectProperty(POSTERIZE)] _PosterizeNumColors("Number of Colors", Range(0,200)) = 8 + [EffectProperty(POSTERIZE)] _PosterizeGamma("Posterize Gamma", Range(0.1,10)) = 0.75 + + //Hand Drawn + [Effect(EffectID# HAND_DRAWN, GroupID# UVEffects)][Toggle(_HAND_DRAWN_ON)]_HandDrawn("Hand Drawn", Float) = 0 + [EffectProperty(HAND_DRAWN)]_HandDrawnAmount("Hand Drawn Amount", Range(0, 50)) = 10 + [EffectProperty(HAND_DRAWN)]_HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 + + //Distortion + [Effect(EffectID# UV_DISTORTION, GroupID# UVEffects)][Toggle(_UV_DISTORTION_ON)]_UVDistortion("Distortion", Float) = 0 + [EffectProperty(UV_DISTORTION)]_DistortTex("Distortion Texture", 2D) = "white" {} + [EffectProperty(UV_DISTORTION)]_DistortAmount("Distortion Amount", Range(0,4)) = 0.3 + [EffectProperty(UV_DISTORTION)]_DistortTexXSpeed("Scroll speed X", Range(-10,10)) = 2 + [EffectProperty(UV_DISTORTION)]_DistortTexYSpeed("Scroll speed Y", Range(-10,10)) = 2 + + //Vertex Shake + [Effect(EffectID# VERTEX_SHAKE, GroupID# MeshEffects)][Toggle(_VERTEX_SHAKE_ON)] _VertexShakeOn("Vertex Shake", Float) = 0 + [EffectProperty(VERTEX_SHAKE)][Vector3] _ShakeSpeed("Speed", Vector) = (41, 49, 45, 0) + [EffectProperty(VERTEX_SHAKE)] _ShakeSpeedMult("Shake Mult", Float) = 1.0 + [EffectProperty(VERTEX_SHAKE)][Vector3] _ShakeMaxDisplacement("Shake Max Displacement", Vector) = (0.1, 0.1, 0.1, 0) + [EffectProperty(VERTEX_SHAKE)] _ShakeBlend("Shake Blend", Range(0, 1)) = 1.0 + + //Vertex Inflate + [Effect(EffectID# VERTEX_INFLATE, GroupID# MeshEffects)][Toggle(_VERTEX_INFLATE_ON)] _VertexInflate("Vertex Inflate", Float) = 0 + [EffectProperty(VERTEX_INFLATE)]_MinInflate("Min Inflate", Float) = 0.0 + [EffectProperty(VERTEX_INFLATE)]_MaxInflate("Max Inflate", Float) = 0.2 + [EffectProperty(VERTEX_INFLATE)]_InflateBlend("Inflate blend", Range(0, 1)) = 1.0 + + //Vertex Distortion + [Effect(EffectID# VERTEX_DISTORTION, GroupID# MeshEffects)][Toggle(_VERTEX_DISTORTION_ON)]_VertexDistortionOn("Vertex Distortion", Float) = 0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseTex("Noise Tex", 2D) = "white" {} + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionAmount("Distortion Amount", Range(0, 2)) = 0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseSpeedX("Scroll Speed X", Range(-10, 10)) = 4.0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseSpeedY("Scroll Speed Y", Range(-10, 10)) = 4.0 + + + //Voxelize + [Effect(EffectID# VOXELIZE, GroupID# MeshEffects)][Toggle(_VOXELIZE_ON)] _Voxelize("Voxelize", Float) = 0 + [EffectProperty(VOXELIZE)]_VoxelSize("Voxel Size", Range(0.1, 500)) = 100 + [EffectProperty(VOXELIZE)]_VoxelBlend("Blend Amount", Range(0, 1)) = 1 + + //Glitch + [Effect(EffectID# GLITCH, GroupID# MeshEffects)][Toggle(_GLITCH_ON)]_Glitch("Glitch", Float) = 0 + [EffectProperty(GLITCH)]_GlitchTiling ("Glitch Tiling", Float) = 5 + [EffectProperty(GLITCH)]_GlitchAmount ("Glitch Amount", Range(0, 1)) = 0.5 + [EffectProperty(GLITCH)]_GlitchOffset ("Glitch Offset", Vector) = (-0.5, 0, 0, 0) + [EffectProperty(GLITCH)]_GlitchSpeed ("Glitch Speed", Float) = 2.5 + [EffectProperty(GLITCH)][Toggle]_GlitchWorldSpace ("Use World Space", Float) = 1 + + //Recalculate Normals + [Effect(EffectID# RECALCULATE_NORMALS, GroupID# MeshEffects)][Toggle(_RECALCULATE_NORMALS_ON)]_RecalculateNormals("Recalculate Normals", Float) = 0 + + //Wind + [Effect(EffectID# WIND, GroupID# MeshEffects)][Toggle(_WIND_ON)]_WindOn("Wind", Float) = 0 + [EffectProperty(WIND)]_WindAttenuation("Attenuation", Range(0, 1)) = 1.0 + [EffectProperty(WIND)][Toggle(_USE_WIND_VERTICAL_MASK)]_UseVerticalMask("Use Vertical Mask?", Float) = 1.0 + [EffectProperty(ParentEffect# WIND, Keywords(_USE_WIND_VERTICAL_MASK), AllowReset# True)]_WindVerticalMaskMinY("Min Y", Float) = -1.0 + [EffectProperty(ParentEffect# WIND, Keywords(_USE_WIND_VERTICAL_MASK), AllowReset# True)]_WindVerticalMaskMaxY("Max Y", Float) = 1.0 + + //Hue Shift + [Effect(EffectID# HUE_SHIFT, GroupID# ColorEffects)][Toggle(_HUE_SHIFT_ON)] _HueShiftEnabled("Hue Shift", Float) = 0 + [EffectProperty(HUE_SHIFT)]_HueShift("Hue Shift", Range(0, 360)) = 0 + [EffectProperty(HUE_SHIFT)]_HueSaturation("Saturation", Range(0, 4)) = 1 + [EffectProperty(HUE_SHIFT)]_HueBrightness("Brightness", Range(0, 2)) = 1 + + //Emission + [Effect(EffectID# EMISSION, GroupID# ColorEffects)][Toggle(_EMISSION_ON)] _EmissionEnabled("Emission", Float) = 0 + [EffectProperty(EMISSION)]_EmissionSelfGlow("Emission Self Glow", Range(0, 20)) = 1 + [EffectProperty(EMISSION)][HDR]_EmissionColor("Emission Color", Color) = (1, 1, 1, 1) + [EffectProperty(EMISSION)]_EmissionMap("Emission Map", 2D) = "white" {} + + //Hologram + [Effect(EffectID# HOLOGRAM, GroupID# ColorEffects)][Toggle(_HOLOGRAM_ON)] _Hologram("Hologram", Float) = 0 + [EffectProperty(HOLOGRAM)][HDR]_HologramColor("Hologram Color", Color) = (1.25,2.8,6.8,1) + [EffectProperty(HOLOGRAM)]_HologramLineDirection("Line Direction", Vector) = (0,1,0,0) + [EffectProperty(HOLOGRAM)]_HologramBaseAlpha("Hologram Base Alpha", Range(0, 1)) = 0.1 + + [EffectProperty(HOLOGRAM)]_HologramScrollSpeed("Hologram Scroll Speed", Float) = 2 + [EffectProperty(HOLOGRAM)]_HologramFrequency("Hologram Frequency", Float) = 20 + [EffectProperty(HOLOGRAM)]_HologramAlpha("Hologram Alpha", Range(0, 1)) = 1 + + [EffectProperty(HOLOGRAM)]_HologramAccentSpeed("Hologram Accent Speed", Float) = 1 + [EffectProperty(HOLOGRAM)]_HologramAccentFrequency("Hologram Accent Frequency", Float) = 2 + [EffectProperty(HOLOGRAM)]_HologramAccentAlpha("Hologram Accent Alpha", Range(0, 1)) = 0.5 + + [EffectProperty(HOLOGRAM)]_HologramLineCenter("Hologram Line Center", Range(0, 1)) = 0.5 + [EffectProperty(HOLOGRAM)]_HologramLineSpacing("Hologram Line Spacing", Range(0.001, 5)) = 2.0 + [EffectProperty(HOLOGRAM)]_HologramLineSmoothness("Hologram Line Smoothness", Range(0.01, 5)) = 2.0 + + //Matcap + [Effect(EffectID# MATCAP, GroupID# ColorEffects)][Toggle(_MATCAP_ON)]_Matcap("Matcap", Float) = 0 + [EffectProperty(MATCAP)][KeywordEnum(Multiply, Replace)]_MatcapBlendMode("Blend Mode", Float) = 0 + [EffectProperty(MATCAP)][NoScaleOffset]_MatcapTex("Matcap Tex", 2D) = "white" {} + [EffectProperty(MATCAP)]_MatcapIntensity("Matcap Intensity", Range(0, 10)) = 1.0 + [EffectProperty(MATCAP)]_MatcapBlend("Matcap Blend", Range(0, 1)) = 1.0 + + //Hit + [Effect(EffectID# HIT, GroupID# ColorEffects)][Toggle(_HIT_ON)] _Hit("Hit", Float) = 0 + [EffectProperty(HIT)]_HitColor("Hit Color", Color) = (1, 1, 1, 1) + [EffectProperty(HIT)]_HitGlow("Hit Glow", Range(0, 100)) = 5 + [EffectProperty(HIT)]_HitBlend("Hit Blend", Range(0, 1)) = 1.0 + + //Contrast and Brightness + [Effect(EffectID# CONTRAST_BRIGHTNESS, GroupID# ColorEffects)][Toggle(_CONTRAST_BRIGHTNESS_ON)]_ContrastBrightnessOn("Contrast and Brightness", Float) = 0 + [EffectProperty(CONTRAST_BRIGHTNESS)]_Contrast("Contrast", Range(0, 10)) = 1.0 + [EffectProperty(CONTRAST_BRIGHTNESS)]_Brightness("Brightness", Range(-1, 1)) = 0.0 + + //Height Gradient + [Effect(EffectID# HEIGHT_GRADIENT, GroupID# ColorEffects)][Toggle(_HEIGHT_GRADIENT_ON)]_HeightGradientOn("Height Gradient", Float) = 0 + [EffectProperty(HEIGHT_GRADIENT)][KeywordEnum(Local, World)]_HeightGradientPositionSpace("Position Space", Float) = 0 + [EffectProperty(HEIGHT_GRADIENT)]_MinGradientHeight("Min Height", Float) = 0.0 + [EffectProperty(HEIGHT_GRADIENT)]_MaxGradientHeight("Max Height", Float) = 0.75 + [EffectProperty(HEIGHT_GRADIENT)][HDR]_GradientHeightColor01("Gradient Color 01", Color) = (0.2, 0.2, 0.2, 1) + [EffectProperty(HEIGHT_GRADIENT)][HDR]_GradientHeightColor02("Gradient Color 02", Color) = (1, 1, 1, 1) + + //Intersection Glow + [Effect(EffectID# INTERSECTION_GLOW, GroupID# ColorEffects)][Toggle(_INTERSECTION_GLOW_ON)]_IntersectionGlowOn("Intersection Glow", Float) = 0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowDist("Depth Distance", Range(0.01, 10)) = 0.2 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowPower("Depth Power", Float) = 25.0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowColor("Depth Glow Color", Color) = (1.0, 0.987, 0.6, 1.0) + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowColorIntensity("Color Intensity", Float) = 25.0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowGlobalIntensity("Global Intensity", Float) = 2.0 + + //Albedo from Vertex Color + [Effect(EffectID# ALBEDO_VERTEX_COLOR, GroupID# ColorEffects)][Toggle(_ALBEDO_VERTEX_COLOR_ON)]_AlbedoVertexColorOn("Albedo From Vertex Color", Float) = 0 + [EffectProperty(ALBEDO_VERTEX_COLOR)][KeywordEnum(Multiply, Replace)]_AlbedoVertexColorMode("Mode", Float) = 1 + [EffectProperty(ALBEDO_VERTEX_COLOR)]_VertexColorBlending("Blending", Range(0, 1)) = 1.0 + + //Triplanar Mapping + [Effect(EffectID# TRIPLANAR_MAPPING, GroupID# ColorEffects, IncompatibleWith# SCREEN_SPACE_UV, CustomDrawer# TRIPLANAR_EFFECT_DRAWER)][Toggle(_TRIPLANAR_MAPPING_ON)]_TriplanarMappingOn("Triplanar Mapping", Float) = 0 + [EffectProperty(TRIPLANAR_MAPPING)][KeywordEnum(Local, World)] _TriplanarNormalSpace("UV Space", Float) = 1.0 + [EffectProperty(TRIPLANAR_MAPPING)]_TriplanarTopTex("Top Texture", 2D) = "white" {} + [NoScaleOffset][EffectProperty(TRIPLANAR_MAPPING)]_TriplanarTopNormalMap("Top Normal Map", 2D) = "bump" {} + [EffectProperty(TRIPLANAR_MAPPING)]_TopNormalStrength("Top Normal Map Strength", Range(0.0, 10.0)) = 1.0 + [EffectProperty(TRIPLANAR_MAPPING)]_FaceDownCutoff("Face Down Cutoff", Range(-1, 1)) = 0.25 + [EffectProperty(TRIPLANAR_MAPPING)]_TriplanarSharpness("Sharpness", Range(1, 200)) = 15.0 + [EffectProperty(TRIPLANAR_MAPPING)][Toggle(_TRIPLANAR_NOISE_TRANSITION_ON)]_TriplanarNoiseTransitionOn("Noise Transition", Float) = 0 + [EffectProperty(ParentEffect# TRIPLANAR_MAPPING, Keywords(_TRIPLANAR_NOISE_TRANSITION_ON), AllowReset# True)] _TriplanarNoiseTex("Noise Tex", 2D) = "white" {} + [EffectProperty(ParentEffect# TRIPLANAR_MAPPING, Keywords(_TRIPLANAR_NOISE_TRANSITION_ON), AllowReset# True)] _TriplanarTransitionPower("Transition Power", Range(0, 1.0)) = 0.75 + + //Texture Blending + [Effect(EffectID# TEXTURE_BLENDING, GroupID# ColorEffects, CustomDrawer# TEXTURE_BLENDING_EFFECT_DRAWER)][Toggle(_TEXTURE_BLENDING_ON)]_TextureBlending ("Texture Blending", Float) = 0 + [EffectProperty(TEXTURE_BLENDING)][KeywordEnum(VertexColor, Texture)]_TextureBlendingSource("Source", Float) = 0 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE), AllowReset# True)]_TexBlendingMask("Texture Blending Mask", 2D) = "white" {} + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffG("Cutoff (G)", Range(0, 1)) = 0.1 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessG("Smoothness (G)", Range(0, 1)) = 0.4 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffB("Cutoff (B)", Range(0, 1)) = 0.1 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessB("Smoothness (B)", Range(0, 1)) = 0.4 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffWhite("Cutoff (White)", Range(0, 1)) = 0.15 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessWhite("Smoothness (White)", Range(0, 1)) = 0.4 + [EffectProperty(TEXTURE_BLENDING)][KeywordEnum(RGB, BlackAndWhite)]_TextureBlendingMode("Blending Mode", Float) = 0 + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureG("Blending Texture (G)", 2D) = "white" {} + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureB("Blending Texture (B)", 2D) = "white" {} + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureWhite("Blending Texture (White)", 2D) = "white" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapG("Blending Normal Map (G)", 2D) = "bump" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapB("Blending Normal Map (B)", 2D) = "bump" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapWhite("Blending Normal Map (White)", 2D) = "bump" {} + + //Depth Coloring + [Effect(EffectID# DEPTH_COLORING, GroupID# ColorEffects)][Toggle(_DEPTH_COLORING_ON)]_DepthColoringOn("Depth Coloring", Float) = 0 + + //Sub surface scattering + [Effect(EffectID# SUBSURFACE_SCATTERING, GroupID# ColorEffects)][Toggle(_SUBSURFACE_SCATTERING_ON)]_SubsurfaceScattering("Fake Subsurface Scattering", Float) = 0.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_NormalInfluence("Normal Influence", Range(0, 2.5)) = 0.5 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSPower("SSS Power", Range(0.01, 20)) = 1.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSFrontPower("SSS Front Power", Range(0.2, 20)) = 3.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSFrontAtten("SSS Front Atten", Range(0, 1)) = 0.3 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSAtten("SSS General Atten", Range(0, 1)) = 1.0 + [EffectProperty(SUBSURFACE_SCATTERING)][HDR]_SSSColor("SSS Color", Color) = (1.0, 1.0, 1.0, 1.0) + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSMap("SSS Map", 2D) = "white" {} + + //Alpha Cutoff + [Effect(EffectID# ALPHA_CUTOFF, GroupID# AlphaEffects)][Toggle(_ALPHA_CUTOFF_ON)]_AlphaCutoffOn("Alpha Cutoff", Float) = 1.0 + [EffectProperty(ALPHA_CUTOFF)]_AlphaCutoffValue("Cutoff Value", Range(0, 1)) = 0.25 + + //Fade + [Effect(EffectID# FADE, GroupID# AlphaEffects)][Toggle(_FADE_ON)]_FadeOn("Fade", Float) = 0 + [EffectProperty(FADE)]_FadeTex("Fade Tex", 2D) = "white" {} + [EffectProperty(FADE)][KeywordEnum(UV1, UV2, WORLD_SPACE)]_FadeUVSet("UV Set", Float) = 0 + [EffectProperty(FADE)]_FadeAmount("Fade Amount", Range(0, 1)) = 0.0 + [EffectProperty(FADE)]_FadePower("Fade Power", Range(0.25, 4.0)) = 1.0 + [EffectProperty(FADE)]_FadeTransition("Fade Transition", Range(0, 0.4)) = 0.2 + [EffectProperty(FADE)][Toggle(_FADE_BURN_ON)]_FadeBurnOn("Use Fade Burn Color?", Float) = 0.0 + [EffectProperty(ParentEffect# FADE, Keywords(_FADE_BURN_ON), AllowReset# True)][HDR]_FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) + [EffectProperty(ParentEffect# FADE, Keywords(_FADE_BURN_ON), AllowReset# True)]_FadeBurnWidth("Fade Burn Width", Range(0, 0.2)) = 0.01 + + //Intersection Fade + [Effect(EffectID# INTERSECTION_FADE, GroupID# AlphaEffects)][Toggle(_INTERSECTION_FADE_ON)]_IntersectionFadeOn("Intersection Fade", Float) = 0.0 + [EffectProperty(INTERSECTION_FADE)]_IntersectionFadeFactor("Intersection Fade Factor", Range(0.1, 3.0)) = 1.0 + + //Alpha Round + [Effect(EffectID# ALPHA_ROUND, GroupID# AlphaEffects)][Toggle(_ALPHA_ROUND_ON)]_AlphaRoundOn("Alpha Round", Float) = 0 + + //Fade By Cam Distance + [Effect(EffectID# FADE_BY_CAM_DISTANCE, GroupID# AlphaEffects)][Toggle(_FADE_BY_CAM_DISTANCE_ON)]_FadeByCamDistanceOn("Fade By Cam Distance", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)][Toggle(_FADE_BY_CAM_DISTANCE_NEAR_FADE)]_NearFade("Near Fade", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)]_MinDistanceToFade("Min Distance", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)]_MaxDistanceToFade("Max Distance", Float) = 100 + + //Dither + [Effect(EffectID# DITHER, GroupID# AlphaEffects)][Toggle(_DITHER_ON)]_DitherOn("Dither", Float) = 0 + [EffectProperty(DITHER)]_DitherScale("Scale", Range(0.01, 2)) = 1 + + // + [Effect(EffectID# OUTLINETYPE, GroupID# OtherEffects, ExtraPasses# (OUTLINE))][KeywordEnum(None, Simple, Constant, FadeWithDistance)]_OutlineType("Outline Type", Float) = 0 + + // + [PerRendererData]_TimingSeed("Timing Seed", Float) = 0 + + + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)][HDR]_OutlineColor("Outline Color", Color) = (0, 0, 0, 1) + [EffectProperty(OUTLINETYPE, CONSTANT)]_MaxCameraDistance("Max Camera Distance", Float) = 1000 + [EffectProperty(OUTLINETYPE, FADEWITHDISTANCE)]_MaxFadeDistance("Max Fade Distance", Float) = 250 + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)]_OutlineThickness("Outline Thickness", Float) = 1 + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)][Enum(Basic, 8, Clean, 6)]_OutlineMode("Outline Mode", Float) = 8 + [IntRange]_StencilRef("Stencil Reference Value", Range(1, 255)) = 1 + } + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "12.0" + } + + Pass + { + Name "AllIn13D_MainPass_URP" + Tags + { + "RenderType" = "Opaque" + "RenderPipeline" = "UniversalPipeline" + } + + Blend [_BlendSrc] [_BlendDst] + Cull [_CullingMode] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + ColorMask [_ColorMask] + + Stencil +{ + Ref [_StencilRef] + Comp Always + Pass Replace +} + + HLSLPROGRAM + #define URP_PASS + #define ALLIN1_FORWARD_PASS + + #pragma vertex BasicVertex + #pragma fragment BasicFragment + + + #if UNITY_VERSION >= 60000000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #endif + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #if defined(LOD_FADE_CROSSFADE) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + #endif + + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_BasePass.hlsl" + + ENDHLSL + } + + Pass + { + Name "AllIn13D_Outline_URP" + Tags {"LightMode"="OutlinePass"} + + Blend [_BlendSrc] [_BlendDst] + Cull Front + + Stencil + { + Ref [_StencilRef] + Comp [_OutlineMode] + } + + HLSLPROGRAM + #pragma vertex OutlinePass_Vertex + #pragma fragment OutlinePass_Fragment + + #define URP_PASS + #define ALLIN1_OUTLINE_PASS + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_OutlinePass.hlsl" + + ENDHLSL + } + + Pass + { + Name "AllIn13D_ShadowCaster_URP" + Tags { "LightMode"="ShadowCaster" } + + ZWrite On + ZTest LEqual + ColorMask 0 + Cull [_CullingMode] + + HLSLPROGRAM + #define URP_PASS + #define SHADOW_CASTER_PASS + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + #pragma vertex BasicVertexShadowCaster + #pragma fragment BasicFragmentShadowCaster + + + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #if defined(LOD_FADE_CROSSFADE) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + #endif + + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl" + + ENDHLSL + } + + Pass + { + Name "DepthOnly" + Tags + { + "LightMode" = "DepthOnly" + } + + // ------------------------------------- + // Render State Commands + ZWrite On + ColorMask R + Cull[_CullingMode] + + HLSLPROGRAM + #define ALLIN1_DEPTH_ONLY_PASS + + // ------------------------------------- + // Shader Stages + #pragma vertex DepthOnlyVertex + #pragma fragment DepthOnlyFragment + + #define URP_PASS + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + // ------------------------------------- + // Includes + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl" + ENDHLSL + } + + Pass + { + Name "DepthNormals" + Tags + { + "LightMode" = "DepthNormals" + } + + ZWrite On + Cull[_CullingMode] + + HLSLPROGRAM + #define ALLIN1_DEPTH_NORMALS_PASS + + // Shader Stages + #pragma vertex DepthNormalsVertex + #pragma fragment DepthNormalsFragment + + #define URP_PASS + + #if UNITY_VERSION >= 60000000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #endif + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + //Includes + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl" + + ENDHLSL + } + + Pass + { + Name "Meta" + Tags{ "LightMode" = "Meta" } + + Cull Off + + HLSLPROGRAM + #pragma exclude_renderers gles gles3 glcore + #define URP_PASS + + #pragma vertex AllIn1VertexMeta + #pragma fragment AllIn1FragmentMeta + #pragma shader_feature EDITOR_VISUALIZATION + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl" + + ENDHLSL + } + } + + SubShader + { + Pass + { + Name "AllIn13D_Forward_BIRP" + Tags { "LightMode" = "ForwardBase" } + + + Stencil +{ + Ref [_StencilRef] + Comp Always + Pass Replace +} + + + Blend [_BlendSrc] [_BlendDst] + Cull [_CullingMode] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + ColorMask [_ColorMask] + + HLSLPROGRAM + #pragma target 3.0 + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #define BIRP_PASS + #define BUILTIN_MAIN_PASS + + #pragma vertex BasicVertex + #pragma fragment BasicFragment + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_BasePass.hlsl" + + ENDHLSL + } + + Pass + { + Name "AllIn13D_Outline" + + Blend [_BlendSrc] [_BlendDst] + Cull Front + + Stencil + { + Ref [_StencilRef] + Comp [_OutlineMode] + } + + HLSLPROGRAM + #pragma target 3.0 + + #pragma multi_compile_instancing + #pragma multi_compile_fog + #pragma multi_compile _ DOTS_INSTANCING_ON + + #pragma vertex OutlinePass_Vertex + #pragma fragment OutlinePass_Fragment + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_OutlinePass.hlsl" + ENDHLSL + } + + + + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd"} + + Blend One One + ZWrite Off + ZTest LEqual + Cull [_CullingMode] + + HLSLPROGRAM + #pragma target 3.0 + + #define BIRP_PASS + #define FORWARD_ADD_PASS + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + + #pragma vertex BasicVertex + #pragma fragment BasicFragmentAdd + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLightAddPass.hlsl" + + ENDHLSL + } + + Pass + { + Name "AllIn13D_ShadowCaster" + Tags { "LightMode"="ShadowCaster" } + + ZWrite On + ZTest LEqual + ColorMask 0 + Cull[_CullingMode] + + HLSLPROGRAM + #pragma target 3.0 + + #define BIRP_PASS + #define SHADOW_CASTER_PASS + + #pragma vertex BasicVertexShadowCaster + #pragma fragment BasicFragmentShadowCaster + + #pragma multi_compile_instancing + #pragma multi_compile_shadowcaster + #pragma multi_compile _ DOTS_INSTANCING_ON + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl" + + ENDHLSL + } + } + + CustomEditor "AllIn13DShader.AllIn13DShaderMaterialInspector" +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline.shader.meta b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline.shader.meta new file mode 100644 index 0000000..7c6ba19 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline.shader.meta @@ -0,0 +1,17 @@ +fileFormatVersion: 2 +guid: a4c8f68acf7c9844e97a36914026acb1 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline.shader + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline_NoShadowCaster.shader b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline_NoShadowCaster.shader new file mode 100644 index 0000000..5fb825d --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline_NoShadowCaster.shader @@ -0,0 +1,730 @@ +Shader "AllIn13DShader/AllIn13DShaderOutline_NoShadowCaster" +{ + Properties + { + _RenderPreset("Render Preset", Float) = 1 + [AdvancedProperty]_AdvancedConfigurationEnabled("Show Advanced Configuration", Float) = 0 + [Enum(UnityEngine.Rendering.BlendMode)]_BlendSrc ("Blend mode Source", Float) = 1 + [Enum(UnityEngine.Rendering.BlendMode)]_BlendDst ("Blend mode Destination", Float) = 0 + [AdvancedProperty][Enum(UnityEngine.Rendering.CullMode)]_CullingMode("Culling Mode", Float) = 2 + [AdvancedProperty][Enum(Off, 0, On, 1)]_ZWrite("Depth Write", float) = 1.0 + [AdvancedProperty][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestMode("Z Test Mode", float) = 4 + [AdvancedProperty][Enum(UnityEngine.Rendering.ColorWriteMask)]_ColorMask("Color Write Mask", float) = 15 + [AdvancedProperty][Toggle(_FOG_ON)] _FogOn("Fog On", Float) = 0 + [AdvancedProperty][Toggle(_SPHERIZE_NORMALS_ON)]_SpherizeNormals("Spherize Normals", Float) = 0.0 + [AdvancedProperty][Toggle(_USE_CUSTOM_TIME)] _UseCustomTime("Use Custom Time", Float) = 0 + + [SingleProperty]_MainTex ("Main Texture", 2D) = "white" {} + [SingleProperty]_Color("Color", Color) = (1, 1, 1, 1) + [SingleProperty]_GeneralAlpha("General Alpha", Range(0, 1)) = 1.0 + + //Color Ramp + [Effect(EffectID# COLOR_RAMP, GroupID# ColorEffects, CustomDrawer# COLOR_RAMP_EFFECT_DRAWER)][Toggle(_COLOR_RAMP_ON)]_ColorRampOn("Color Ramp", Float) = 0 + [EffectProperty(ParentEffect# COLOR_RAMP, Keywords(_COLOR_RAMP_ON), AllowReset# False)][KeywordEnum(BeforeLighting, AfterLighting)]_ColorRampLightingStage("Stage", Float) = 0.0 + [EffectProperty(COLOR_RAMP)][AllIn13DShaderGradientDrawer]_ColorRampTex("Color Ramp Tex", 2D) = "white" {} + [EffectProperty(COLOR_RAMP)]_ColorRampLuminosity("Color Ramp Luminosity", Range(0, 1)) = 0 + [EffectProperty(COLOR_RAMP)]_ColorRampBlend("Color Ramp Blend", Range(0, 1)) = 1 + [EffectProperty(COLOR_RAMP)]_ColorRampTiling("Tiling", Range(0.01, 10)) = 1.0 + [EffectProperty(COLOR_RAMP)]_ColorRampScrollSpeed("Scroll Speed", Float) = 0.0 + + //Lighting + [Effect(EffectID# LIGHTMODEL, GroupID# Lighting, ExtraPasses# (FORWARD_ADD))][KeywordEnum(None, Classic, Toon, ToonRamp, HalfLambert, FakeGI, FastLighting)] _LightModel ("Light Model", Float) = 1 + [EffectProperty(LIGHTMODEL, TOON)]_ToonCutoff("Toon Cutoff", Range(0, 1)) = 0.5 + [EffectProperty(LIGHTMODEL, TOON)]_ToonSmoothness("Toon Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(LIGHTMODEL, TOONRAMP)][AllIn13DShaderGradientDrawer]_ToonRamp("Toon Ramp", 2D) = "white" {} + [EffectProperty(LIGHTMODEL, HALFLAMBERT)]_HalfLambertWrap("Half Lambert", Range(0, 1)) = 1 + [EffectProperty(LIGHTMODEL, FAKEGI)]_HardnessFakeGI("Fake GI Hardness", Range(0, 1)) = 0.75 + + //Shading Model + [Effect(EffectID# SHADINGMODEL, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(Basic, PBR)] _ShadingModel("Shading Model", Float) = 0 + [EffectProperty(SHADINGMODEL, PBR)]_Metallic("Metallic", Range(0, 1)) = 0 + [EffectProperty(SHADINGMODEL, PBR)]_Smoothness("Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(ParentEffect# SHADINGMODEL, Keywords(_SHADINGMODEL_PBR), AllowReset# True)][Toggle(_METALLIC_MAP_ON)]_MetallicMapOn("Use Metallic(R) / Smoothness(A) Map?", Float) = 0.0 + [EffectProperty(ParentEffect# SHADINGMODEL, KeywordsOp# AND, Keywords(_SHADINGMODEL_PBR, _METALLIC_MAP_ON), AllowReset# True)]_MetallicMap("Metallic Map", 2D) = "white" {} + + //Specular + [Effect(EffectID# SPECULARMODEL, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(None, Classic, Toon, Anisotropic, AnisotropicToon)]_SpecularModel ("Specular Model", Float) = 0 + [EffectProperty(SPECULARMODEL, CLASSIC, TOON, ANISOTROPIC, ANISOTROPICTOON)]_SpecularAtten("Specular Attenuation", Range(0, 1)) = 0.5 + [EffectProperty(ParentEffect# SPECULARMODEL, IncompatibleWithKws(_SHADINGMODEL_PBR), Keywords(_SPECULARMODEL_CLASSIC, _SPECULARMODEL_TOON), AllowReset# True)]_Shininess("Shininess", Range(0.01, 25)) = 16.0 + [EffectProperty(ParentEffect# SPECULARMODEL, IncompatibleWithKws(_SHADINGMODEL_PBR), Keywords(_SPECULARMODEL_ANISOTROPIC, _SPECULARMODEL_ANISOTROPICTOON), AllowReset# True)]_AnisoShininess("Aniso Shininess", Range(0, 1)) = 0.85 + [EffectProperty(SPECULARMODEL, TOON, ANISOTROPICTOON)]_SpecularToonCutoff("Specular Toon Cutoff", Range(0, 1)) = 0.35 + [EffectProperty(SPECULARMODEL, TOON, ANISOTROPICTOON)]_SpecularToonSmoothness("Specular Toon Smoothness", Range(0, 1)) = 0.0 + [EffectProperty(SPECULARMODEL, CLASSIC, TOON, ANISOTROPIC, ANISOTROPICTOON)]_SpecularMap("Specular Map", 2D) = "white" {} + [EffectProperty(SPECULARMODEL, ANISOTROPIC, ANISOTROPICTOON)]_Anisotropy("Anisotropy", Range(-1, 1)) = 0.45 + + //Reflections + [Effect(EffectID# REFLECTIONS, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(None, Classic, Toon)]_Reflections("Reflections", Float) = 0.0 + [EffectProperty(REFLECTIONS, TOON)]_ToonFactor("Toon Factor", Range(0, 1)) = 0 + [EffectProperty(REFLECTIONS, CLASSIC, TOON)]_ReflectionsAtten("Attenuation", Range(0, 1)) = 0.5 + + //Normal Map + [Effect(EffectID# NORMAL_MAP, GroupID# Lighting, DependentOn# LIGHTMODEL, CustomDrawer# NORMAL_MAP_EFFECT_DRAWER)][Toggle(_NORMAL_MAP_ON)]_NormalMapEnabled("Normal Map", Float) = 0 + [NoScaleOffset][EffectProperty(NORMAL_MAP)]_NormalMap("Normal Map", 2D) = "bump" {} + [EffectProperty(NORMAL_MAP)]_NormalStrength("Normal Strength", Range(0.0, 10.0)) = 1.0 + + //Flat Normals + [Effect(EffectID# FLAT_NORMALS, GroupID# Lighting, DependentOn# LIGHTMODEL)][Toggle(_FLAT_NORMALS_ON)]_FlatNormalsEnabled("Flat Normals", Float) = 0 + [EffectProperty(FLAT_NORMALS)]_FlatNormalsBlend("Blending", Range(0, 1)) = 1.0 + + //Custom Shadow Color + [Effect(EffectID# CUSTOM_SHADOW_COLOR, GroupID# Lighting)][Toggle(_CUSTOM_SHADOW_COLOR_ON)]_CustomShadowColorOn("Custom Shadow Color", Float) = 0 + + //Lightmaps + [Effect(EffectID# AFFECTED_BY_LIGHTMAPS, GroupID# Lighting)][Toggle(_AFFECTED_BY_LIGHTMAPS_ON)]_AffectedByLightmaps("Affected by lightmaps", Float) = 0 + [EffectProperty(AFFECTED_BY_LIGHTMAPS)][Toggle(_LIGHTMAP_COLOR_CORRECTION_ON)]_LightmapColorCorrection("Lightmap Color Correction?", Float) = 0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueShiftLM("Hue Shift", Range(0, 360)) = 0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueSaturationLM("Hue Saturation", Range(0, 4)) = 1 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueBrightnessLM("Hue Brightness", Range(0, 2)) = 1 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_ContrastLM("Contrast", Range(0, 20)) = 1.0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_BrightnessLM("Brightness", Range(-2, 2)) = 0.0 + + //Affected By Ambient + [Effect(EffectID# CUSTOM_AMBIENT_LIGHT, GroupID# Lighting)][Toggle(_CUSTOM_AMBIENT_LIGHT_ON)]_CustomAmbientLightOn("Custom Ambient Light", Float) = 0.0 + [EffectProperty(CUSTOM_AMBIENT_LIGHT)]_CustomAmbientColor("Custom Ambient Color", Color) = (0.65, 0.65, 0.65, 1.0) + + //Cast Shadows Enabled + [Effect(EffectID# CAST_SHADOWS_ON, GroupID# Lighting, ExtraPasses# (SHADOW_CASTER))][Toggle(_CAST_SHADOWS_ON)]_CastShadowsOn("Cast Shadows", Float) = 1.0 + + //Receive Shadows + [Effect(EffectID# RECEIVE_SHADOWS, GroupID# Lighting, ExtraPasses# (SHADOW_CASTER))][Toggle(_RECEIVE_SHADOWS_ON)]_ReceiveShadows("Receive Shadows", Float) = 1.0 + [EffectProperty(RECEIVE_SHADOWS)][KeywordEnum(Classic, Stylized)] _ReceivedShadowsType("Shadow Type", Float) = 0 + [EffectProperty(ParentEffect# RECEIVE_SHADOWS, Keywords(_RECEIVEDSHADOWSTYPE_STYLIZED), AllowReset# True)] _ShadowCutoff("Cutoff", Range(0.001, 0.5)) = 0.2 + + //Scroll Texture + [Effect(EffectID# SCROLL_TEXTURE, GroupID# UVEffects)][Toggle(_SCROLL_TEXTURE_ON)]_ScrollTextureOn("Scroll Texture", Float) = 0 + [EffectProperty(SCROLL_TEXTURE)]_ScrollTextureX("Scroll X", Float) = 1.0 + [EffectProperty(SCROLL_TEXTURE)]_ScrollTextureY("Scroll Y", Float) = 1.0 + + //Screen Space UVs + [Effect(EffectID# SCREEN_SPACE_UV, GroupID# UVEffects, IncompatibleWith# TRIPLANAR_MAPPING)][Toggle(_SCREEN_SPACE_UV_ON)]_ScreenSpaceUVOn("Screen Space UV", Float) = 0.0 + [EffectProperty(SCREEN_SPACE_UV)]_ScaleWithCameraDistance("Scale with camera distance", Range(0, 1)) = 0.0 + + //Pixelate + [Effect(EffectID# PIXELATE, GroupID# UVEffects)][Toggle(_PIXELATE_ON)]_Pixelate("Pixelate", Float) = 0 + [EffectProperty(PIXELATE)]_PixelateSize("Pixelate Size", Range(4, 512)) = 32 + + //Stochastic Texture Sampling + [Effect(EffectID# STOCHASTIC_SAMPLING, GroupID# UVEffects)][Toggle(_STOCHASTIC_SAMPLING_ON)]_StochasticSampling("Stochastic Sampling", Float) = 0 + [EffectProperty(STOCHASTIC_SAMPLING)]_StochasticScale("Grid Scale", Range(0, 10)) = 3.464 + [EffectProperty(STOCHASTIC_SAMPLING)]_StochasticSkew("Grid Skew", Range(0, 3)) = 0.57735027 + + //Wave UV + [Effect(EffectID# WAVE_UV, GroupID# UVEffects)][Toggle(_WAVE_UV_ON)]_WaveUVOn("Wave UV On", Float) = 0 + [EffectProperty(WAVE_UV)]_WaveAmount("Wave Amount", Range(0, 25)) = 7 + [EffectProperty(WAVE_UV)]_WaveSpeed("Wave Speed", Range(0, 25)) = 10 + [EffectProperty(WAVE_UV)]_WaveStrength("Wave Strength", Range(0, 25)) = 7.5 + [EffectProperty(WAVE_UV)]_WaveX("Wave X Axis", Range(0, 1)) = 0 + [EffectProperty(WAVE_UV)]_WaveY("Wave Y Axis", Range(0, 1)) = 0.5 + + //AO Map + [Effect(EffectID# AOMAP, GroupID# ColorEffects)][Toggle(_AOMAP_ON)]_AOMapEnabled("AO Map", Float) = 0 + [EffectProperty(AOMAP)][NoScaleOffset]_AOMap("AO Map", 2D) = "white" {} + [EffectProperty(AOMAP)]_AOMapStrength("AO Strength", Range(0, 1)) = 1.0 + [EffectProperty(AOMAP)]_AOContrast("AO Contrast", Range(0, 1)) = 1.0 + [EffectProperty(AOMAP)]_AOColor("AO Color", Color) = (0, 0, 0, 0) + + //Highlights + [Effect(EffectID# HIGHLIGHTS, GroupID# ColorEffects)][Toggle(_HIGHLIGHTS_ON)]_Highlights("Highlights", Float) = 0 + [EffectProperty(HIGHLIGHTS)][HDR]_HighlightsColor("Highlights Color", Color) = (2, 2, 2, 1) + [EffectProperty(HIGHLIGHTS)]_HighlightsStrength("Highlights Strength", Range(0, 1)) = 1 + [EffectProperty(HIGHLIGHTS)]_HighlightCutoff("Highlight Cutoff", Range(0, 1)) = 0.5 + [EffectProperty(HIGHLIGHTS)]_HighlightSmoothness("Highlight Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(HIGHLIGHTS)][Vector3]_HighlightOffset("Highlight Offset", Vector) = (0, 0, 0, 0) + + //Rim + [Effect(EffectID# RIM_LIGHTING, GroupID# ColorEffects)][Toggle(_RIM_LIGHTING_ON)]_RimLighting("Rim or Fresnel", Float) = 0 + [EffectProperty(ParentEffect# RIM_LIGHTING, Keywords(_RIM_LIGHTING_ON), AllowReset# False)][KeywordEnum(BeforeLighting, BeforeLightingLast, AfterLighting)]_RimLightingStage("Stage", Float) = 0.0 + [EffectProperty(RIM_LIGHTING)][HDR]_RimColor("Rim Color", Color) = (1, 1, 1, 1) + [EffectProperty(RIM_LIGHTING)]_RimAttenuation("Rim Attenuation", Range(0, 1)) = 1.0 + [EffectProperty(RIM_LIGHTING)]_MinRim("Min Rim", Range(0, 1)) = 0 + [EffectProperty(RIM_LIGHTING)]_MaxRim("Max Rim", Range(0, 1)) = 1.0 + [EffectProperty(RIM_LIGHTING)][Vector3]_RimOffset("Rim Offset", Vector) = (0, 0, 0, 0) + + //Greyscale + [Effect(EffectID# GREYSCALE, GroupID# ColorEffects)][Toggle(_GREYSCALE_ON)]_Greyscale("Greyscale", Float) = 0 + [EffectProperty(GREYSCALE)][KeywordEnum(BeforeLighting, AfterLighting)] _GreyScaleStage("Stage", Float) = 0 + [EffectProperty(GREYSCALE)] _GreyscaleLuminosity("Luminosity", Range(-1, 1)) = 0 + [EffectProperty(GREYSCALE)] _GreyscaleTintColor("Greyscale Tint", Color) = (1.0, 1.0, 1.0, 1.0) + [EffectProperty(GREYSCALE)] _GreyscaleBlending("Blending", Range(0, 1)) = 1 + + //Posterize + [Effect(EffectID# POSTERIZE, GroupID# ColorEffects)][Toggle(_POSTERIZE_ON)]_Posterize("Posterize", Float) = 0 + [EffectProperty(POSTERIZE)] _PosterizeNumColors("Number of Colors", Range(0,200)) = 8 + [EffectProperty(POSTERIZE)] _PosterizeGamma("Posterize Gamma", Range(0.1,10)) = 0.75 + + //Hand Drawn + [Effect(EffectID# HAND_DRAWN, GroupID# UVEffects)][Toggle(_HAND_DRAWN_ON)]_HandDrawn("Hand Drawn", Float) = 0 + [EffectProperty(HAND_DRAWN)]_HandDrawnAmount("Hand Drawn Amount", Range(0, 50)) = 10 + [EffectProperty(HAND_DRAWN)]_HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 + + //Distortion + [Effect(EffectID# UV_DISTORTION, GroupID# UVEffects)][Toggle(_UV_DISTORTION_ON)]_UVDistortion("Distortion", Float) = 0 + [EffectProperty(UV_DISTORTION)]_DistortTex("Distortion Texture", 2D) = "white" {} + [EffectProperty(UV_DISTORTION)]_DistortAmount("Distortion Amount", Range(0,4)) = 0.3 + [EffectProperty(UV_DISTORTION)]_DistortTexXSpeed("Scroll speed X", Range(-10,10)) = 2 + [EffectProperty(UV_DISTORTION)]_DistortTexYSpeed("Scroll speed Y", Range(-10,10)) = 2 + + //Vertex Shake + [Effect(EffectID# VERTEX_SHAKE, GroupID# MeshEffects)][Toggle(_VERTEX_SHAKE_ON)] _VertexShakeOn("Vertex Shake", Float) = 0 + [EffectProperty(VERTEX_SHAKE)][Vector3] _ShakeSpeed("Speed", Vector) = (41, 49, 45, 0) + [EffectProperty(VERTEX_SHAKE)] _ShakeSpeedMult("Shake Mult", Float) = 1.0 + [EffectProperty(VERTEX_SHAKE)][Vector3] _ShakeMaxDisplacement("Shake Max Displacement", Vector) = (0.1, 0.1, 0.1, 0) + [EffectProperty(VERTEX_SHAKE)] _ShakeBlend("Shake Blend", Range(0, 1)) = 1.0 + + //Vertex Inflate + [Effect(EffectID# VERTEX_INFLATE, GroupID# MeshEffects)][Toggle(_VERTEX_INFLATE_ON)] _VertexInflate("Vertex Inflate", Float) = 0 + [EffectProperty(VERTEX_INFLATE)]_MinInflate("Min Inflate", Float) = 0.0 + [EffectProperty(VERTEX_INFLATE)]_MaxInflate("Max Inflate", Float) = 0.2 + [EffectProperty(VERTEX_INFLATE)]_InflateBlend("Inflate blend", Range(0, 1)) = 1.0 + + //Vertex Distortion + [Effect(EffectID# VERTEX_DISTORTION, GroupID# MeshEffects)][Toggle(_VERTEX_DISTORTION_ON)]_VertexDistortionOn("Vertex Distortion", Float) = 0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseTex("Noise Tex", 2D) = "white" {} + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionAmount("Distortion Amount", Range(0, 2)) = 0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseSpeedX("Scroll Speed X", Range(-10, 10)) = 4.0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseSpeedY("Scroll Speed Y", Range(-10, 10)) = 4.0 + + + //Voxelize + [Effect(EffectID# VOXELIZE, GroupID# MeshEffects)][Toggle(_VOXELIZE_ON)] _Voxelize("Voxelize", Float) = 0 + [EffectProperty(VOXELIZE)]_VoxelSize("Voxel Size", Range(0.1, 500)) = 100 + [EffectProperty(VOXELIZE)]_VoxelBlend("Blend Amount", Range(0, 1)) = 1 + + //Glitch + [Effect(EffectID# GLITCH, GroupID# MeshEffects)][Toggle(_GLITCH_ON)]_Glitch("Glitch", Float) = 0 + [EffectProperty(GLITCH)]_GlitchTiling ("Glitch Tiling", Float) = 5 + [EffectProperty(GLITCH)]_GlitchAmount ("Glitch Amount", Range(0, 1)) = 0.5 + [EffectProperty(GLITCH)]_GlitchOffset ("Glitch Offset", Vector) = (-0.5, 0, 0, 0) + [EffectProperty(GLITCH)]_GlitchSpeed ("Glitch Speed", Float) = 2.5 + [EffectProperty(GLITCH)][Toggle]_GlitchWorldSpace ("Use World Space", Float) = 1 + + //Recalculate Normals + [Effect(EffectID# RECALCULATE_NORMALS, GroupID# MeshEffects)][Toggle(_RECALCULATE_NORMALS_ON)]_RecalculateNormals("Recalculate Normals", Float) = 0 + + //Wind + [Effect(EffectID# WIND, GroupID# MeshEffects)][Toggle(_WIND_ON)]_WindOn("Wind", Float) = 0 + [EffectProperty(WIND)]_WindAttenuation("Attenuation", Range(0, 1)) = 1.0 + [EffectProperty(WIND)][Toggle(_USE_WIND_VERTICAL_MASK)]_UseVerticalMask("Use Vertical Mask?", Float) = 1.0 + [EffectProperty(ParentEffect# WIND, Keywords(_USE_WIND_VERTICAL_MASK), AllowReset# True)]_WindVerticalMaskMinY("Min Y", Float) = -1.0 + [EffectProperty(ParentEffect# WIND, Keywords(_USE_WIND_VERTICAL_MASK), AllowReset# True)]_WindVerticalMaskMaxY("Max Y", Float) = 1.0 + + //Hue Shift + [Effect(EffectID# HUE_SHIFT, GroupID# ColorEffects)][Toggle(_HUE_SHIFT_ON)] _HueShiftEnabled("Hue Shift", Float) = 0 + [EffectProperty(HUE_SHIFT)]_HueShift("Hue Shift", Range(0, 360)) = 0 + [EffectProperty(HUE_SHIFT)]_HueSaturation("Saturation", Range(0, 4)) = 1 + [EffectProperty(HUE_SHIFT)]_HueBrightness("Brightness", Range(0, 2)) = 1 + + //Emission + [Effect(EffectID# EMISSION, GroupID# ColorEffects)][Toggle(_EMISSION_ON)] _EmissionEnabled("Emission", Float) = 0 + [EffectProperty(EMISSION)]_EmissionSelfGlow("Emission Self Glow", Range(0, 20)) = 1 + [EffectProperty(EMISSION)][HDR]_EmissionColor("Emission Color", Color) = (1, 1, 1, 1) + [EffectProperty(EMISSION)]_EmissionMap("Emission Map", 2D) = "white" {} + + //Hologram + [Effect(EffectID# HOLOGRAM, GroupID# ColorEffects)][Toggle(_HOLOGRAM_ON)] _Hologram("Hologram", Float) = 0 + [EffectProperty(HOLOGRAM)][HDR]_HologramColor("Hologram Color", Color) = (1.25,2.8,6.8,1) + [EffectProperty(HOLOGRAM)]_HologramLineDirection("Line Direction", Vector) = (0,1,0,0) + [EffectProperty(HOLOGRAM)]_HologramBaseAlpha("Hologram Base Alpha", Range(0, 1)) = 0.1 + + [EffectProperty(HOLOGRAM)]_HologramScrollSpeed("Hologram Scroll Speed", Float) = 2 + [EffectProperty(HOLOGRAM)]_HologramFrequency("Hologram Frequency", Float) = 20 + [EffectProperty(HOLOGRAM)]_HologramAlpha("Hologram Alpha", Range(0, 1)) = 1 + + [EffectProperty(HOLOGRAM)]_HologramAccentSpeed("Hologram Accent Speed", Float) = 1 + [EffectProperty(HOLOGRAM)]_HologramAccentFrequency("Hologram Accent Frequency", Float) = 2 + [EffectProperty(HOLOGRAM)]_HologramAccentAlpha("Hologram Accent Alpha", Range(0, 1)) = 0.5 + + [EffectProperty(HOLOGRAM)]_HologramLineCenter("Hologram Line Center", Range(0, 1)) = 0.5 + [EffectProperty(HOLOGRAM)]_HologramLineSpacing("Hologram Line Spacing", Range(0.001, 5)) = 2.0 + [EffectProperty(HOLOGRAM)]_HologramLineSmoothness("Hologram Line Smoothness", Range(0.01, 5)) = 2.0 + + //Matcap + [Effect(EffectID# MATCAP, GroupID# ColorEffects)][Toggle(_MATCAP_ON)]_Matcap("Matcap", Float) = 0 + [EffectProperty(MATCAP)][KeywordEnum(Multiply, Replace)]_MatcapBlendMode("Blend Mode", Float) = 0 + [EffectProperty(MATCAP)][NoScaleOffset]_MatcapTex("Matcap Tex", 2D) = "white" {} + [EffectProperty(MATCAP)]_MatcapIntensity("Matcap Intensity", Range(0, 10)) = 1.0 + [EffectProperty(MATCAP)]_MatcapBlend("Matcap Blend", Range(0, 1)) = 1.0 + + //Hit + [Effect(EffectID# HIT, GroupID# ColorEffects)][Toggle(_HIT_ON)] _Hit("Hit", Float) = 0 + [EffectProperty(HIT)]_HitColor("Hit Color", Color) = (1, 1, 1, 1) + [EffectProperty(HIT)]_HitGlow("Hit Glow", Range(0, 100)) = 5 + [EffectProperty(HIT)]_HitBlend("Hit Blend", Range(0, 1)) = 1.0 + + //Contrast and Brightness + [Effect(EffectID# CONTRAST_BRIGHTNESS, GroupID# ColorEffects)][Toggle(_CONTRAST_BRIGHTNESS_ON)]_ContrastBrightnessOn("Contrast and Brightness", Float) = 0 + [EffectProperty(CONTRAST_BRIGHTNESS)]_Contrast("Contrast", Range(0, 10)) = 1.0 + [EffectProperty(CONTRAST_BRIGHTNESS)]_Brightness("Brightness", Range(-1, 1)) = 0.0 + + //Height Gradient + [Effect(EffectID# HEIGHT_GRADIENT, GroupID# ColorEffects)][Toggle(_HEIGHT_GRADIENT_ON)]_HeightGradientOn("Height Gradient", Float) = 0 + [EffectProperty(HEIGHT_GRADIENT)][KeywordEnum(Local, World)]_HeightGradientPositionSpace("Position Space", Float) = 0 + [EffectProperty(HEIGHT_GRADIENT)]_MinGradientHeight("Min Height", Float) = 0.0 + [EffectProperty(HEIGHT_GRADIENT)]_MaxGradientHeight("Max Height", Float) = 0.75 + [EffectProperty(HEIGHT_GRADIENT)][HDR]_GradientHeightColor01("Gradient Color 01", Color) = (0.2, 0.2, 0.2, 1) + [EffectProperty(HEIGHT_GRADIENT)][HDR]_GradientHeightColor02("Gradient Color 02", Color) = (1, 1, 1, 1) + + //Intersection Glow + [Effect(EffectID# INTERSECTION_GLOW, GroupID# ColorEffects)][Toggle(_INTERSECTION_GLOW_ON)]_IntersectionGlowOn("Intersection Glow", Float) = 0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowDist("Depth Distance", Range(0.01, 10)) = 0.2 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowPower("Depth Power", Float) = 25.0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowColor("Depth Glow Color", Color) = (1.0, 0.987, 0.6, 1.0) + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowColorIntensity("Color Intensity", Float) = 25.0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowGlobalIntensity("Global Intensity", Float) = 2.0 + + //Albedo from Vertex Color + [Effect(EffectID# ALBEDO_VERTEX_COLOR, GroupID# ColorEffects)][Toggle(_ALBEDO_VERTEX_COLOR_ON)]_AlbedoVertexColorOn("Albedo From Vertex Color", Float) = 0 + [EffectProperty(ALBEDO_VERTEX_COLOR)][KeywordEnum(Multiply, Replace)]_AlbedoVertexColorMode("Mode", Float) = 1 + [EffectProperty(ALBEDO_VERTEX_COLOR)]_VertexColorBlending("Blending", Range(0, 1)) = 1.0 + + //Triplanar Mapping + [Effect(EffectID# TRIPLANAR_MAPPING, GroupID# ColorEffects, IncompatibleWith# SCREEN_SPACE_UV, CustomDrawer# TRIPLANAR_EFFECT_DRAWER)][Toggle(_TRIPLANAR_MAPPING_ON)]_TriplanarMappingOn("Triplanar Mapping", Float) = 0 + [EffectProperty(TRIPLANAR_MAPPING)][KeywordEnum(Local, World)] _TriplanarNormalSpace("UV Space", Float) = 1.0 + [EffectProperty(TRIPLANAR_MAPPING)]_TriplanarTopTex("Top Texture", 2D) = "white" {} + [NoScaleOffset][EffectProperty(TRIPLANAR_MAPPING)]_TriplanarTopNormalMap("Top Normal Map", 2D) = "bump" {} + [EffectProperty(TRIPLANAR_MAPPING)]_TopNormalStrength("Top Normal Map Strength", Range(0.0, 10.0)) = 1.0 + [EffectProperty(TRIPLANAR_MAPPING)]_FaceDownCutoff("Face Down Cutoff", Range(-1, 1)) = 0.25 + [EffectProperty(TRIPLANAR_MAPPING)]_TriplanarSharpness("Sharpness", Range(1, 200)) = 15.0 + [EffectProperty(TRIPLANAR_MAPPING)][Toggle(_TRIPLANAR_NOISE_TRANSITION_ON)]_TriplanarNoiseTransitionOn("Noise Transition", Float) = 0 + [EffectProperty(ParentEffect# TRIPLANAR_MAPPING, Keywords(_TRIPLANAR_NOISE_TRANSITION_ON), AllowReset# True)] _TriplanarNoiseTex("Noise Tex", 2D) = "white" {} + [EffectProperty(ParentEffect# TRIPLANAR_MAPPING, Keywords(_TRIPLANAR_NOISE_TRANSITION_ON), AllowReset# True)] _TriplanarTransitionPower("Transition Power", Range(0, 1.0)) = 0.75 + + //Texture Blending + [Effect(EffectID# TEXTURE_BLENDING, GroupID# ColorEffects, CustomDrawer# TEXTURE_BLENDING_EFFECT_DRAWER)][Toggle(_TEXTURE_BLENDING_ON)]_TextureBlending ("Texture Blending", Float) = 0 + [EffectProperty(TEXTURE_BLENDING)][KeywordEnum(VertexColor, Texture)]_TextureBlendingSource("Source", Float) = 0 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE), AllowReset# True)]_TexBlendingMask("Texture Blending Mask", 2D) = "white" {} + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffG("Cutoff (G)", Range(0, 1)) = 0.1 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessG("Smoothness (G)", Range(0, 1)) = 0.4 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffB("Cutoff (B)", Range(0, 1)) = 0.1 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessB("Smoothness (B)", Range(0, 1)) = 0.4 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffWhite("Cutoff (White)", Range(0, 1)) = 0.15 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessWhite("Smoothness (White)", Range(0, 1)) = 0.4 + [EffectProperty(TEXTURE_BLENDING)][KeywordEnum(RGB, BlackAndWhite)]_TextureBlendingMode("Blending Mode", Float) = 0 + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureG("Blending Texture (G)", 2D) = "white" {} + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureB("Blending Texture (B)", 2D) = "white" {} + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureWhite("Blending Texture (White)", 2D) = "white" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapG("Blending Normal Map (G)", 2D) = "bump" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapB("Blending Normal Map (B)", 2D) = "bump" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapWhite("Blending Normal Map (White)", 2D) = "bump" {} + + //Depth Coloring + [Effect(EffectID# DEPTH_COLORING, GroupID# ColorEffects)][Toggle(_DEPTH_COLORING_ON)]_DepthColoringOn("Depth Coloring", Float) = 0 + + //Sub surface scattering + [Effect(EffectID# SUBSURFACE_SCATTERING, GroupID# ColorEffects)][Toggle(_SUBSURFACE_SCATTERING_ON)]_SubsurfaceScattering("Fake Subsurface Scattering", Float) = 0.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_NormalInfluence("Normal Influence", Range(0, 2.5)) = 0.5 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSPower("SSS Power", Range(0.01, 20)) = 1.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSFrontPower("SSS Front Power", Range(0.2, 20)) = 3.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSFrontAtten("SSS Front Atten", Range(0, 1)) = 0.3 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSAtten("SSS General Atten", Range(0, 1)) = 1.0 + [EffectProperty(SUBSURFACE_SCATTERING)][HDR]_SSSColor("SSS Color", Color) = (1.0, 1.0, 1.0, 1.0) + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSMap("SSS Map", 2D) = "white" {} + + //Alpha Cutoff + [Effect(EffectID# ALPHA_CUTOFF, GroupID# AlphaEffects)][Toggle(_ALPHA_CUTOFF_ON)]_AlphaCutoffOn("Alpha Cutoff", Float) = 1.0 + [EffectProperty(ALPHA_CUTOFF)]_AlphaCutoffValue("Cutoff Value", Range(0, 1)) = 0.25 + + //Fade + [Effect(EffectID# FADE, GroupID# AlphaEffects)][Toggle(_FADE_ON)]_FadeOn("Fade", Float) = 0 + [EffectProperty(FADE)]_FadeTex("Fade Tex", 2D) = "white" {} + [EffectProperty(FADE)][KeywordEnum(UV1, UV2, WORLD_SPACE)]_FadeUVSet("UV Set", Float) = 0 + [EffectProperty(FADE)]_FadeAmount("Fade Amount", Range(0, 1)) = 0.0 + [EffectProperty(FADE)]_FadePower("Fade Power", Range(0.25, 4.0)) = 1.0 + [EffectProperty(FADE)]_FadeTransition("Fade Transition", Range(0, 0.4)) = 0.2 + [EffectProperty(FADE)][Toggle(_FADE_BURN_ON)]_FadeBurnOn("Use Fade Burn Color?", Float) = 0.0 + [EffectProperty(ParentEffect# FADE, Keywords(_FADE_BURN_ON), AllowReset# True)][HDR]_FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) + [EffectProperty(ParentEffect# FADE, Keywords(_FADE_BURN_ON), AllowReset# True)]_FadeBurnWidth("Fade Burn Width", Range(0, 0.2)) = 0.01 + + //Intersection Fade + [Effect(EffectID# INTERSECTION_FADE, GroupID# AlphaEffects)][Toggle(_INTERSECTION_FADE_ON)]_IntersectionFadeOn("Intersection Fade", Float) = 0.0 + [EffectProperty(INTERSECTION_FADE)]_IntersectionFadeFactor("Intersection Fade Factor", Range(0.1, 3.0)) = 1.0 + + //Alpha Round + [Effect(EffectID# ALPHA_ROUND, GroupID# AlphaEffects)][Toggle(_ALPHA_ROUND_ON)]_AlphaRoundOn("Alpha Round", Float) = 0 + + //Fade By Cam Distance + [Effect(EffectID# FADE_BY_CAM_DISTANCE, GroupID# AlphaEffects)][Toggle(_FADE_BY_CAM_DISTANCE_ON)]_FadeByCamDistanceOn("Fade By Cam Distance", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)][Toggle(_FADE_BY_CAM_DISTANCE_NEAR_FADE)]_NearFade("Near Fade", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)]_MinDistanceToFade("Min Distance", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)]_MaxDistanceToFade("Max Distance", Float) = 100 + + //Dither + [Effect(EffectID# DITHER, GroupID# AlphaEffects)][Toggle(_DITHER_ON)]_DitherOn("Dither", Float) = 0 + [EffectProperty(DITHER)]_DitherScale("Scale", Range(0.01, 2)) = 1 + + // + [Effect(EffectID# OUTLINETYPE, GroupID# OtherEffects, ExtraPasses# (OUTLINE))][KeywordEnum(None, Simple, Constant, FadeWithDistance)]_OutlineType("Outline Type", Float) = 0 + + // + [PerRendererData]_TimingSeed("Timing Seed", Float) = 0 + + + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)][HDR]_OutlineColor("Outline Color", Color) = (0, 0, 0, 1) + [EffectProperty(OUTLINETYPE, CONSTANT)]_MaxCameraDistance("Max Camera Distance", Float) = 1000 + [EffectProperty(OUTLINETYPE, FADEWITHDISTANCE)]_MaxFadeDistance("Max Fade Distance", Float) = 250 + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)]_OutlineThickness("Outline Thickness", Float) = 1 + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)][Enum(Basic, 8, Clean, 6)]_OutlineMode("Outline Mode", Float) = 8 + [IntRange]_StencilRef("Stencil Reference Value", Range(1, 255)) = 1 + } + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "12.0" + } + + Pass + { + Name "AllIn13D_MainPass_URP" + Tags + { + "RenderType" = "Opaque" + "RenderPipeline" = "UniversalPipeline" + } + + Blend [_BlendSrc] [_BlendDst] + Cull [_CullingMode] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + ColorMask [_ColorMask] + + Stencil +{ + Ref [_StencilRef] + Comp Always + Pass Replace +} + + HLSLPROGRAM + #define URP_PASS + #define ALLIN1_FORWARD_PASS + + #pragma vertex BasicVertex + #pragma fragment BasicFragment + + + #if UNITY_VERSION >= 60000000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #endif + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #if defined(LOD_FADE_CROSSFADE) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + #endif + + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_BasePass.hlsl" + + ENDHLSL + } + + Pass + { + Name "AllIn13D_Outline_URP" + Tags {"LightMode"="OutlinePass"} + + Blend [_BlendSrc] [_BlendDst] + Cull Front + + Stencil + { + Ref [_StencilRef] + Comp NotEqual + } + + HLSLPROGRAM + #pragma vertex OutlinePass_Vertex + #pragma fragment OutlinePass_Fragment + + #define URP_PASS + #define ALLIN1_OUTLINE_PASS + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_OutlinePass.hlsl" + + ENDHLSL + } + + Pass + { + Name "DepthOnly" + Tags + { + "LightMode" = "DepthOnly" + } + + // ------------------------------------- + // Render State Commands + ZWrite On + ColorMask R + Cull[_CullingMode] + + HLSLPROGRAM + #define ALLIN1_DEPTH_ONLY_PASS + + // ------------------------------------- + // Shader Stages + #pragma vertex DepthOnlyVertex + #pragma fragment DepthOnlyFragment + + #define URP_PASS + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + // ------------------------------------- + // Includes + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl" + ENDHLSL + } + + Pass + { + Name "DepthNormals" + Tags + { + "LightMode" = "DepthNormals" + } + + ZWrite On + Cull[_CullingMode] + + HLSLPROGRAM + #define ALLIN1_DEPTH_NORMALS_PASS + + // Shader Stages + #pragma vertex DepthNormalsVertex + #pragma fragment DepthNormalsFragment + + #define URP_PASS + + #if UNITY_VERSION >= 60000000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #endif + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + //Includes + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl" + + ENDHLSL + } + + Pass + { + Name "Meta" + Tags{ "LightMode" = "Meta" } + + Cull Off + + HLSLPROGRAM + #pragma exclude_renderers gles gles3 glcore + #define URP_PASS + + #pragma vertex AllIn1VertexMeta + #pragma fragment AllIn1FragmentMeta + #pragma shader_feature EDITOR_VISUALIZATION + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl" + + ENDHLSL + } + } + + SubShader + { + Pass + { + Name "AllIn13D_Forward_BIRP" + Tags { "LightMode" = "ForwardBase" } + + + Stencil +{ + Ref [_StencilRef] + Comp Always + Pass Replace +} + + + Blend [_BlendSrc] [_BlendDst] + Cull [_CullingMode] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + ColorMask [_ColorMask] + + HLSLPROGRAM + #pragma target 3.0 + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #define BIRP_PASS + #define BUILTIN_MAIN_PASS + + #pragma vertex BasicVertex + #pragma fragment BasicFragment + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_BasePass.hlsl" + + ENDHLSL + } + + Pass + { + Name "AllIn13D_Outline" + + Blend [_BlendSrc] [_BlendDst] + Cull Front + + Stencil + { + Ref [_StencilRef] + Comp [_OutlineMode] + } + + HLSLPROGRAM + #pragma target 3.0 + + #pragma multi_compile_instancing + #pragma multi_compile_fog + #pragma multi_compile _ DOTS_INSTANCING_ON + + #pragma vertex OutlinePass_Vertex + #pragma fragment OutlinePass_Fragment + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_OutlinePass.hlsl" + ENDHLSL + } + + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd"} + + Blend One One + ZWrite Off + ZTest LEqual + Cull [_CullingMode] + + HLSLPROGRAM + #pragma target 3.0 + + #define BIRP_PASS + #define FORWARD_ADD_PASS + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + + #pragma vertex BasicVertex + #pragma fragment BasicFragmentAdd + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLightAddPass.hlsl" + + ENDHLSL + } + } + + CustomEditor "AllIn13DShader.AllIn13DShaderMaterialInspector" +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline_NoShadowCaster.shader.meta b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline_NoShadowCaster.shader.meta new file mode 100644 index 0000000..86f287e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline_NoShadowCaster.shader.meta @@ -0,0 +1,17 @@ +fileFormatVersion: 2 +guid: 7fd6f68952c76af4c8005466df606651 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShaderOutline_NoShadowCaster.shader + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader_NoShadowCaster.shader b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader_NoShadowCaster.shader new file mode 100644 index 0000000..2302684 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader_NoShadowCaster.shader @@ -0,0 +1,639 @@ +Shader "AllIn13DShader/AllIn13DShader_NoShadowCaster" +{ + Properties + { + _RenderPreset("Render Preset", Float) = 1 + [AdvancedProperty]_AdvancedConfigurationEnabled("Show Advanced Configuration", Float) = 0 + [Enum(UnityEngine.Rendering.BlendMode)]_BlendSrc ("Blend mode Source", Float) = 1 + [Enum(UnityEngine.Rendering.BlendMode)]_BlendDst ("Blend mode Destination", Float) = 0 + [AdvancedProperty][Enum(UnityEngine.Rendering.CullMode)]_CullingMode("Culling Mode", Float) = 2 + [AdvancedProperty][Enum(Off, 0, On, 1)]_ZWrite("Depth Write", float) = 1.0 + [AdvancedProperty][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestMode("Z Test Mode", float) = 4 + [AdvancedProperty][Enum(UnityEngine.Rendering.ColorWriteMask)]_ColorMask("Color Write Mask", float) = 15 + [AdvancedProperty][Toggle(_FOG_ON)] _FogOn("Fog On", Float) = 0 + [AdvancedProperty][Toggle(_SPHERIZE_NORMALS_ON)]_SpherizeNormals("Spherize Normals", Float) = 0.0 + [AdvancedProperty][Toggle(_USE_CUSTOM_TIME)] _UseCustomTime("Use Custom Time", Float) = 0 + + [SingleProperty]_MainTex ("Main Texture", 2D) = "white" {} + [SingleProperty]_Color("Color", Color) = (1, 1, 1, 1) + [SingleProperty]_GeneralAlpha("General Alpha", Range(0, 1)) = 1.0 + + //Color Ramp + [Effect(EffectID# COLOR_RAMP, GroupID# ColorEffects, CustomDrawer# COLOR_RAMP_EFFECT_DRAWER)][Toggle(_COLOR_RAMP_ON)]_ColorRampOn("Color Ramp", Float) = 0 + [EffectProperty(ParentEffect# COLOR_RAMP, Keywords(_COLOR_RAMP_ON), AllowReset# False)][KeywordEnum(BeforeLighting, AfterLighting)]_ColorRampLightingStage("Stage", Float) = 0.0 + [EffectProperty(COLOR_RAMP)][AllIn13DShaderGradientDrawer]_ColorRampTex("Color Ramp Tex", 2D) = "white" {} + [EffectProperty(COLOR_RAMP)]_ColorRampLuminosity("Color Ramp Luminosity", Range(0, 1)) = 0 + [EffectProperty(COLOR_RAMP)]_ColorRampBlend("Color Ramp Blend", Range(0, 1)) = 1 + [EffectProperty(COLOR_RAMP)]_ColorRampTiling("Tiling", Range(0.01, 10)) = 1.0 + [EffectProperty(COLOR_RAMP)]_ColorRampScrollSpeed("Scroll Speed", Float) = 0.0 + + //Lighting + [Effect(EffectID# LIGHTMODEL, GroupID# Lighting, ExtraPasses# (FORWARD_ADD))][KeywordEnum(None, Classic, Toon, ToonRamp, HalfLambert, FakeGI, FastLighting)] _LightModel ("Light Model", Float) = 1 + [EffectProperty(LIGHTMODEL, TOON)]_ToonCutoff("Toon Cutoff", Range(0, 1)) = 0.5 + [EffectProperty(LIGHTMODEL, TOON)]_ToonSmoothness("Toon Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(LIGHTMODEL, TOONRAMP)][AllIn13DShaderGradientDrawer]_ToonRamp("Toon Ramp", 2D) = "white" {} + [EffectProperty(LIGHTMODEL, HALFLAMBERT)]_HalfLambertWrap("Half Lambert", Range(0, 1)) = 1 + [EffectProperty(LIGHTMODEL, FAKEGI)]_HardnessFakeGI("Fake GI Hardness", Range(0, 1)) = 0.75 + + //Shading Model + [Effect(EffectID# SHADINGMODEL, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(Basic, PBR)] _ShadingModel("Shading Model", Float) = 0 + [EffectProperty(SHADINGMODEL, PBR)]_Metallic("Metallic", Range(0, 1)) = 0 + [EffectProperty(SHADINGMODEL, PBR)]_Smoothness("Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(ParentEffect# SHADINGMODEL, Keywords(_SHADINGMODEL_PBR), AllowReset# True)][Toggle(_METALLIC_MAP_ON)]_MetallicMapOn("Use Metallic(R) / Smoothness(A) Map?", Float) = 0.0 + [EffectProperty(ParentEffect# SHADINGMODEL, KeywordsOp# AND, Keywords(_SHADINGMODEL_PBR, _METALLIC_MAP_ON), AllowReset# True)]_MetallicMap("Metallic Map", 2D) = "white" {} + + //Specular + [Effect(EffectID# SPECULARMODEL, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(None, Classic, Toon, Anisotropic, AnisotropicToon)]_SpecularModel ("Specular Model", Float) = 0 + [EffectProperty(SPECULARMODEL, CLASSIC, TOON, ANISOTROPIC, ANISOTROPICTOON)]_SpecularAtten("Specular Attenuation", Range(0, 1)) = 0.5 + [EffectProperty(ParentEffect# SPECULARMODEL, IncompatibleWithKws(_SHADINGMODEL_PBR), Keywords(_SPECULARMODEL_CLASSIC, _SPECULARMODEL_TOON), AllowReset# True)]_Shininess("Shininess", Range(0.01, 25)) = 16.0 + [EffectProperty(ParentEffect# SPECULARMODEL, IncompatibleWithKws(_SHADINGMODEL_PBR), Keywords(_SPECULARMODEL_ANISOTROPIC, _SPECULARMODEL_ANISOTROPICTOON), AllowReset# True)]_AnisoShininess("Aniso Shininess", Range(0, 1)) = 0.85 + [EffectProperty(SPECULARMODEL, TOON, ANISOTROPICTOON)]_SpecularToonCutoff("Specular Toon Cutoff", Range(0, 1)) = 0.35 + [EffectProperty(SPECULARMODEL, TOON, ANISOTROPICTOON)]_SpecularToonSmoothness("Specular Toon Smoothness", Range(0, 1)) = 0.0 + [EffectProperty(SPECULARMODEL, CLASSIC, TOON, ANISOTROPIC, ANISOTROPICTOON)]_SpecularMap("Specular Map", 2D) = "white" {} + [EffectProperty(SPECULARMODEL, ANISOTROPIC, ANISOTROPICTOON)]_Anisotropy("Anisotropy", Range(-1, 1)) = 0.45 + + //Reflections + [Effect(EffectID# REFLECTIONS, GroupID# Lighting, DependentOn# LIGHTMODEL)][KeywordEnum(None, Classic, Toon)]_Reflections("Reflections", Float) = 0.0 + [EffectProperty(REFLECTIONS, TOON)]_ToonFactor("Toon Factor", Range(0, 1)) = 0 + [EffectProperty(REFLECTIONS, CLASSIC, TOON)]_ReflectionsAtten("Attenuation", Range(0, 1)) = 0.5 + + //Normal Map + [Effect(EffectID# NORMAL_MAP, GroupID# Lighting, DependentOn# LIGHTMODEL, CustomDrawer# NORMAL_MAP_EFFECT_DRAWER)][Toggle(_NORMAL_MAP_ON)]_NormalMapEnabled("Normal Map", Float) = 0 + [NoScaleOffset][EffectProperty(NORMAL_MAP)]_NormalMap("Normal Map", 2D) = "bump" {} + [EffectProperty(NORMAL_MAP)]_NormalStrength("Normal Strength", Range(0.0, 10.0)) = 1.0 + + //Flat Normals + [Effect(EffectID# FLAT_NORMALS, GroupID# Lighting, DependentOn# LIGHTMODEL)][Toggle(_FLAT_NORMALS_ON)]_FlatNormalsEnabled("Flat Normals", Float) = 0 + [EffectProperty(FLAT_NORMALS)]_FlatNormalsBlend("Blending", Range(0, 1)) = 1.0 + + //Custom Shadow Color + [Effect(EffectID# CUSTOM_SHADOW_COLOR, GroupID# Lighting)][Toggle(_CUSTOM_SHADOW_COLOR_ON)]_CustomShadowColorOn("Custom Shadow Color", Float) = 0 + + //Lightmaps + [Effect(EffectID# AFFECTED_BY_LIGHTMAPS, GroupID# Lighting)][Toggle(_AFFECTED_BY_LIGHTMAPS_ON)]_AffectedByLightmaps("Affected by lightmaps", Float) = 0 + [EffectProperty(AFFECTED_BY_LIGHTMAPS)][Toggle(_LIGHTMAP_COLOR_CORRECTION_ON)]_LightmapColorCorrection("Lightmap Color Correction?", Float) = 0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueShiftLM("Hue Shift", Range(0, 360)) = 0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueSaturationLM("Hue Saturation", Range(0, 4)) = 1 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_HueBrightnessLM("Hue Brightness", Range(0, 2)) = 1 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_ContrastLM("Contrast", Range(0, 20)) = 1.0 + [EffectProperty(ParentEffect# AFFECTED_BY_LIGHTMAPS, Keywords(_LIGHTMAP_COLOR_CORRECTION_ON), AllowReset# True)]_BrightnessLM("Brightness", Range(-2, 2)) = 0.0 + + //Affected By Ambient + [Effect(EffectID# CUSTOM_AMBIENT_LIGHT, GroupID# Lighting)][Toggle(_CUSTOM_AMBIENT_LIGHT_ON)]_CustomAmbientLightOn("Custom Ambient Light", Float) = 0.0 + [EffectProperty(CUSTOM_AMBIENT_LIGHT)]_CustomAmbientColor("Custom Ambient Color", Color) = (0.65, 0.65, 0.65, 1.0) + + //Cast Shadows Enabled + [Effect(EffectID# CAST_SHADOWS_ON, GroupID# Lighting, ExtraPasses# (SHADOW_CASTER))][Toggle(_CAST_SHADOWS_ON)]_CastShadowsOn("Cast Shadows", Float) = 1.0 + + //Receive Shadows + [Effect(EffectID# RECEIVE_SHADOWS, GroupID# Lighting, ExtraPasses# (SHADOW_CASTER))][Toggle(_RECEIVE_SHADOWS_ON)]_ReceiveShadows("Receive Shadows", Float) = 1.0 + [EffectProperty(RECEIVE_SHADOWS)][KeywordEnum(Classic, Stylized)] _ReceivedShadowsType("Shadow Type", Float) = 0 + [EffectProperty(ParentEffect# RECEIVE_SHADOWS, Keywords(_RECEIVEDSHADOWSTYPE_STYLIZED), AllowReset# True)] _ShadowCutoff("Cutoff", Range(0.001, 0.5)) = 0.2 + + //Scroll Texture + [Effect(EffectID# SCROLL_TEXTURE, GroupID# UVEffects)][Toggle(_SCROLL_TEXTURE_ON)]_ScrollTextureOn("Scroll Texture", Float) = 0 + [EffectProperty(SCROLL_TEXTURE)]_ScrollTextureX("Scroll X", Float) = 1.0 + [EffectProperty(SCROLL_TEXTURE)]_ScrollTextureY("Scroll Y", Float) = 1.0 + + //Screen Space UVs + [Effect(EffectID# SCREEN_SPACE_UV, GroupID# UVEffects, IncompatibleWith# TRIPLANAR_MAPPING)][Toggle(_SCREEN_SPACE_UV_ON)]_ScreenSpaceUVOn("Screen Space UV", Float) = 0.0 + [EffectProperty(SCREEN_SPACE_UV)]_ScaleWithCameraDistance("Scale with camera distance", Range(0, 1)) = 0.0 + + //Pixelate + [Effect(EffectID# PIXELATE, GroupID# UVEffects)][Toggle(_PIXELATE_ON)]_Pixelate("Pixelate", Float) = 0 + [EffectProperty(PIXELATE)]_PixelateSize("Pixelate Size", Range(4, 512)) = 32 + + //Stochastic Texture Sampling + [Effect(EffectID# STOCHASTIC_SAMPLING, GroupID# UVEffects)][Toggle(_STOCHASTIC_SAMPLING_ON)]_StochasticSampling("Stochastic Sampling", Float) = 0 + [EffectProperty(STOCHASTIC_SAMPLING)]_StochasticScale("Grid Scale", Range(0, 10)) = 3.464 + [EffectProperty(STOCHASTIC_SAMPLING)]_StochasticSkew("Grid Skew", Range(0, 3)) = 0.57735027 + + //Wave UV + [Effect(EffectID# WAVE_UV, GroupID# UVEffects)][Toggle(_WAVE_UV_ON)]_WaveUVOn("Wave UV On", Float) = 0 + [EffectProperty(WAVE_UV)]_WaveAmount("Wave Amount", Range(0, 25)) = 7 + [EffectProperty(WAVE_UV)]_WaveSpeed("Wave Speed", Range(0, 25)) = 10 + [EffectProperty(WAVE_UV)]_WaveStrength("Wave Strength", Range(0, 25)) = 7.5 + [EffectProperty(WAVE_UV)]_WaveX("Wave X Axis", Range(0, 1)) = 0 + [EffectProperty(WAVE_UV)]_WaveY("Wave Y Axis", Range(0, 1)) = 0.5 + + //AO Map + [Effect(EffectID# AOMAP, GroupID# ColorEffects)][Toggle(_AOMAP_ON)]_AOMapEnabled("AO Map", Float) = 0 + [EffectProperty(AOMAP)][NoScaleOffset]_AOMap("AO Map", 2D) = "white" {} + [EffectProperty(AOMAP)]_AOMapStrength("AO Strength", Range(0, 1)) = 1.0 + [EffectProperty(AOMAP)]_AOContrast("AO Contrast", Range(0, 1)) = 1.0 + [EffectProperty(AOMAP)]_AOColor("AO Color", Color) = (0, 0, 0, 0) + + //Highlights + [Effect(EffectID# HIGHLIGHTS, GroupID# ColorEffects)][Toggle(_HIGHLIGHTS_ON)]_Highlights("Highlights", Float) = 0 + [EffectProperty(HIGHLIGHTS)][HDR]_HighlightsColor("Highlights Color", Color) = (2, 2, 2, 1) + [EffectProperty(HIGHLIGHTS)]_HighlightsStrength("Highlights Strength", Range(0, 1)) = 1 + [EffectProperty(HIGHLIGHTS)]_HighlightCutoff("Highlight Cutoff", Range(0, 1)) = 0.5 + [EffectProperty(HIGHLIGHTS)]_HighlightSmoothness("Highlight Smoothness", Range(0, 1)) = 0.5 + [EffectProperty(HIGHLIGHTS)][Vector3]_HighlightOffset("Highlight Offset", Vector) = (0, 0, 0, 0) + + //Rim + [Effect(EffectID# RIM_LIGHTING, GroupID# ColorEffects)][Toggle(_RIM_LIGHTING_ON)]_RimLighting("Rim or Fresnel", Float) = 0 + [EffectProperty(ParentEffect# RIM_LIGHTING, Keywords(_RIM_LIGHTING_ON), AllowReset# False)][KeywordEnum(BeforeLighting, BeforeLightingLast, AfterLighting)]_RimLightingStage("Stage", Float) = 0.0 + [EffectProperty(RIM_LIGHTING)][HDR]_RimColor("Rim Color", Color) = (1, 1, 1, 1) + [EffectProperty(RIM_LIGHTING)]_RimAttenuation("Rim Attenuation", Range(0, 1)) = 1.0 + [EffectProperty(RIM_LIGHTING)]_MinRim("Min Rim", Range(0, 1)) = 0 + [EffectProperty(RIM_LIGHTING)]_MaxRim("Max Rim", Range(0, 1)) = 1.0 + [EffectProperty(RIM_LIGHTING)][Vector3]_RimOffset("Rim Offset", Vector) = (0, 0, 0, 0) + + //Greyscale + [Effect(EffectID# GREYSCALE, GroupID# ColorEffects)][Toggle(_GREYSCALE_ON)]_Greyscale("Greyscale", Float) = 0 + [EffectProperty(GREYSCALE)][KeywordEnum(BeforeLighting, AfterLighting)] _GreyScaleStage("Stage", Float) = 0 + [EffectProperty(GREYSCALE)] _GreyscaleLuminosity("Luminosity", Range(-1, 1)) = 0 + [EffectProperty(GREYSCALE)] _GreyscaleTintColor("Greyscale Tint", Color) = (1.0, 1.0, 1.0, 1.0) + [EffectProperty(GREYSCALE)] _GreyscaleBlending("Blending", Range(0, 1)) = 1 + + //Posterize + [Effect(EffectID# POSTERIZE, GroupID# ColorEffects)][Toggle(_POSTERIZE_ON)]_Posterize("Posterize", Float) = 0 + [EffectProperty(POSTERIZE)] _PosterizeNumColors("Number of Colors", Range(0,200)) = 8 + [EffectProperty(POSTERIZE)] _PosterizeGamma("Posterize Gamma", Range(0.1,10)) = 0.75 + + //Hand Drawn + [Effect(EffectID# HAND_DRAWN, GroupID# UVEffects)][Toggle(_HAND_DRAWN_ON)]_HandDrawn("Hand Drawn", Float) = 0 + [EffectProperty(HAND_DRAWN)]_HandDrawnAmount("Hand Drawn Amount", Range(0, 50)) = 10 + [EffectProperty(HAND_DRAWN)]_HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 + + //Distortion + [Effect(EffectID# UV_DISTORTION, GroupID# UVEffects)][Toggle(_UV_DISTORTION_ON)]_UVDistortion("Distortion", Float) = 0 + [EffectProperty(UV_DISTORTION)]_DistortTex("Distortion Texture", 2D) = "white" {} + [EffectProperty(UV_DISTORTION)]_DistortAmount("Distortion Amount", Range(0,4)) = 0.3 + [EffectProperty(UV_DISTORTION)]_DistortTexXSpeed("Scroll speed X", Range(-10,10)) = 2 + [EffectProperty(UV_DISTORTION)]_DistortTexYSpeed("Scroll speed Y", Range(-10,10)) = 2 + + //Vertex Shake + [Effect(EffectID# VERTEX_SHAKE, GroupID# MeshEffects)][Toggle(_VERTEX_SHAKE_ON)] _VertexShakeOn("Vertex Shake", Float) = 0 + [EffectProperty(VERTEX_SHAKE)][Vector3] _ShakeSpeed("Speed", Vector) = (41, 49, 45, 0) + [EffectProperty(VERTEX_SHAKE)] _ShakeSpeedMult("Shake Mult", Float) = 1.0 + [EffectProperty(VERTEX_SHAKE)][Vector3] _ShakeMaxDisplacement("Shake Max Displacement", Vector) = (0.1, 0.1, 0.1, 0) + [EffectProperty(VERTEX_SHAKE)] _ShakeBlend("Shake Blend", Range(0, 1)) = 1.0 + + //Vertex Inflate + [Effect(EffectID# VERTEX_INFLATE, GroupID# MeshEffects)][Toggle(_VERTEX_INFLATE_ON)] _VertexInflate("Vertex Inflate", Float) = 0 + [EffectProperty(VERTEX_INFLATE)]_MinInflate("Min Inflate", Float) = 0.0 + [EffectProperty(VERTEX_INFLATE)]_MaxInflate("Max Inflate", Float) = 0.2 + [EffectProperty(VERTEX_INFLATE)]_InflateBlend("Inflate blend", Range(0, 1)) = 1.0 + + //Vertex Distortion + [Effect(EffectID# VERTEX_DISTORTION, GroupID# MeshEffects)][Toggle(_VERTEX_DISTORTION_ON)]_VertexDistortionOn("Vertex Distortion", Float) = 0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseTex("Noise Tex", 2D) = "white" {} + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionAmount("Distortion Amount", Range(0, 2)) = 0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseSpeedX("Scroll Speed X", Range(-10, 10)) = 4.0 + [EffectProperty(VERTEX_DISTORTION)]_VertexDistortionNoiseSpeedY("Scroll Speed Y", Range(-10, 10)) = 4.0 + + + //Voxelize + [Effect(EffectID# VOXELIZE, GroupID# MeshEffects)][Toggle(_VOXELIZE_ON)] _Voxelize("Voxelize", Float) = 0 + [EffectProperty(VOXELIZE)]_VoxelSize("Voxel Size", Range(0.1, 500)) = 100 + [EffectProperty(VOXELIZE)]_VoxelBlend("Blend Amount", Range(0, 1)) = 1 + + //Glitch + [Effect(EffectID# GLITCH, GroupID# MeshEffects)][Toggle(_GLITCH_ON)]_Glitch("Glitch", Float) = 0 + [EffectProperty(GLITCH)]_GlitchTiling ("Glitch Tiling", Float) = 5 + [EffectProperty(GLITCH)]_GlitchAmount ("Glitch Amount", Range(0, 1)) = 0.5 + [EffectProperty(GLITCH)]_GlitchOffset ("Glitch Offset", Vector) = (-0.5, 0, 0, 0) + [EffectProperty(GLITCH)]_GlitchSpeed ("Glitch Speed", Float) = 2.5 + [EffectProperty(GLITCH)][Toggle]_GlitchWorldSpace ("Use World Space", Float) = 1 + + //Recalculate Normals + [Effect(EffectID# RECALCULATE_NORMALS, GroupID# MeshEffects)][Toggle(_RECALCULATE_NORMALS_ON)]_RecalculateNormals("Recalculate Normals", Float) = 0 + + //Wind + [Effect(EffectID# WIND, GroupID# MeshEffects)][Toggle(_WIND_ON)]_WindOn("Wind", Float) = 0 + [EffectProperty(WIND)]_WindAttenuation("Attenuation", Range(0, 1)) = 1.0 + [EffectProperty(WIND)][Toggle(_USE_WIND_VERTICAL_MASK)]_UseVerticalMask("Use Vertical Mask?", Float) = 1.0 + [EffectProperty(ParentEffect# WIND, Keywords(_USE_WIND_VERTICAL_MASK), AllowReset# True)]_WindVerticalMaskMinY("Min Y", Float) = -1.0 + [EffectProperty(ParentEffect# WIND, Keywords(_USE_WIND_VERTICAL_MASK), AllowReset# True)]_WindVerticalMaskMaxY("Max Y", Float) = 1.0 + + //Hue Shift + [Effect(EffectID# HUE_SHIFT, GroupID# ColorEffects)][Toggle(_HUE_SHIFT_ON)] _HueShiftEnabled("Hue Shift", Float) = 0 + [EffectProperty(HUE_SHIFT)]_HueShift("Hue Shift", Range(0, 360)) = 0 + [EffectProperty(HUE_SHIFT)]_HueSaturation("Saturation", Range(0, 4)) = 1 + [EffectProperty(HUE_SHIFT)]_HueBrightness("Brightness", Range(0, 2)) = 1 + + //Emission + [Effect(EffectID# EMISSION, GroupID# ColorEffects)][Toggle(_EMISSION_ON)] _EmissionEnabled("Emission", Float) = 0 + [EffectProperty(EMISSION)]_EmissionSelfGlow("Emission Self Glow", Range(0, 20)) = 1 + [EffectProperty(EMISSION)][HDR]_EmissionColor("Emission Color", Color) = (1, 1, 1, 1) + [EffectProperty(EMISSION)]_EmissionMap("Emission Map", 2D) = "white" {} + + //Hologram + [Effect(EffectID# HOLOGRAM, GroupID# ColorEffects)][Toggle(_HOLOGRAM_ON)] _Hologram("Hologram", Float) = 0 + [EffectProperty(HOLOGRAM)][HDR]_HologramColor("Hologram Color", Color) = (1.25,2.8,6.8,1) + [EffectProperty(HOLOGRAM)]_HologramLineDirection("Line Direction", Vector) = (0,1,0,0) + [EffectProperty(HOLOGRAM)]_HologramBaseAlpha("Hologram Base Alpha", Range(0, 1)) = 0.1 + + [EffectProperty(HOLOGRAM)]_HologramScrollSpeed("Hologram Scroll Speed", Float) = 2 + [EffectProperty(HOLOGRAM)]_HologramFrequency("Hologram Frequency", Float) = 20 + [EffectProperty(HOLOGRAM)]_HologramAlpha("Hologram Alpha", Range(0, 1)) = 1 + + [EffectProperty(HOLOGRAM)]_HologramAccentSpeed("Hologram Accent Speed", Float) = 1 + [EffectProperty(HOLOGRAM)]_HologramAccentFrequency("Hologram Accent Frequency", Float) = 2 + [EffectProperty(HOLOGRAM)]_HologramAccentAlpha("Hologram Accent Alpha", Range(0, 1)) = 0.5 + + [EffectProperty(HOLOGRAM)]_HologramLineCenter("Hologram Line Center", Range(0, 1)) = 0.5 + [EffectProperty(HOLOGRAM)]_HologramLineSpacing("Hologram Line Spacing", Range(0.001, 5)) = 2.0 + [EffectProperty(HOLOGRAM)]_HologramLineSmoothness("Hologram Line Smoothness", Range(0.01, 5)) = 2.0 + + //Matcap + [Effect(EffectID# MATCAP, GroupID# ColorEffects)][Toggle(_MATCAP_ON)]_Matcap("Matcap", Float) = 0 + [EffectProperty(MATCAP)][KeywordEnum(Multiply, Replace)]_MatcapBlendMode("Blend Mode", Float) = 0 + [EffectProperty(MATCAP)][NoScaleOffset]_MatcapTex("Matcap Tex", 2D) = "white" {} + [EffectProperty(MATCAP)]_MatcapIntensity("Matcap Intensity", Range(0, 10)) = 1.0 + [EffectProperty(MATCAP)]_MatcapBlend("Matcap Blend", Range(0, 1)) = 1.0 + + //Hit + [Effect(EffectID# HIT, GroupID# ColorEffects)][Toggle(_HIT_ON)] _Hit("Hit", Float) = 0 + [EffectProperty(HIT)]_HitColor("Hit Color", Color) = (1, 1, 1, 1) + [EffectProperty(HIT)]_HitGlow("Hit Glow", Range(0, 100)) = 5 + [EffectProperty(HIT)]_HitBlend("Hit Blend", Range(0, 1)) = 1.0 + + //Contrast and Brightness + [Effect(EffectID# CONTRAST_BRIGHTNESS, GroupID# ColorEffects)][Toggle(_CONTRAST_BRIGHTNESS_ON)]_ContrastBrightnessOn("Contrast and Brightness", Float) = 0 + [EffectProperty(CONTRAST_BRIGHTNESS)]_Contrast("Contrast", Range(0, 10)) = 1.0 + [EffectProperty(CONTRAST_BRIGHTNESS)]_Brightness("Brightness", Range(-1, 1)) = 0.0 + + //Height Gradient + [Effect(EffectID# HEIGHT_GRADIENT, GroupID# ColorEffects)][Toggle(_HEIGHT_GRADIENT_ON)]_HeightGradientOn("Height Gradient", Float) = 0 + [EffectProperty(HEIGHT_GRADIENT)][KeywordEnum(Local, World)]_HeightGradientPositionSpace("Position Space", Float) = 0 + [EffectProperty(HEIGHT_GRADIENT)]_MinGradientHeight("Min Height", Float) = 0.0 + [EffectProperty(HEIGHT_GRADIENT)]_MaxGradientHeight("Max Height", Float) = 0.75 + [EffectProperty(HEIGHT_GRADIENT)][HDR]_GradientHeightColor01("Gradient Color 01", Color) = (0.2, 0.2, 0.2, 1) + [EffectProperty(HEIGHT_GRADIENT)][HDR]_GradientHeightColor02("Gradient Color 02", Color) = (1, 1, 1, 1) + + //Intersection Glow + [Effect(EffectID# INTERSECTION_GLOW, GroupID# ColorEffects)][Toggle(_INTERSECTION_GLOW_ON)]_IntersectionGlowOn("Intersection Glow", Float) = 0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowDist("Depth Distance", Range(0.01, 10)) = 0.2 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowPower("Depth Power", Float) = 25.0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowColor("Depth Glow Color", Color) = (1.0, 0.987, 0.6, 1.0) + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowColorIntensity("Color Intensity", Float) = 25.0 + [EffectProperty(INTERSECTION_GLOW)]_DepthGlowGlobalIntensity("Global Intensity", Float) = 2.0 + + //Albedo from Vertex Color + [Effect(EffectID# ALBEDO_VERTEX_COLOR, GroupID# ColorEffects)][Toggle(_ALBEDO_VERTEX_COLOR_ON)]_AlbedoVertexColorOn("Albedo From Vertex Color", Float) = 0 + [EffectProperty(ALBEDO_VERTEX_COLOR)][KeywordEnum(Multiply, Replace)]_AlbedoVertexColorMode("Mode", Float) = 1 + [EffectProperty(ALBEDO_VERTEX_COLOR)]_VertexColorBlending("Blending", Range(0, 1)) = 1.0 + + //Triplanar Mapping + [Effect(EffectID# TRIPLANAR_MAPPING, GroupID# ColorEffects, IncompatibleWith# SCREEN_SPACE_UV, CustomDrawer# TRIPLANAR_EFFECT_DRAWER)][Toggle(_TRIPLANAR_MAPPING_ON)]_TriplanarMappingOn("Triplanar Mapping", Float) = 0 + [EffectProperty(TRIPLANAR_MAPPING)][KeywordEnum(Local, World)] _TriplanarNormalSpace("UV Space", Float) = 1.0 + [EffectProperty(TRIPLANAR_MAPPING)]_TriplanarTopTex("Top Texture", 2D) = "white" {} + [NoScaleOffset][EffectProperty(TRIPLANAR_MAPPING)]_TriplanarTopNormalMap("Top Normal Map", 2D) = "bump" {} + [EffectProperty(TRIPLANAR_MAPPING)]_TopNormalStrength("Top Normal Map Strength", Range(0.0, 10.0)) = 1.0 + [EffectProperty(TRIPLANAR_MAPPING)]_FaceDownCutoff("Face Down Cutoff", Range(-1, 1)) = 0.25 + [EffectProperty(TRIPLANAR_MAPPING)]_TriplanarSharpness("Sharpness", Range(1, 200)) = 15.0 + [EffectProperty(TRIPLANAR_MAPPING)][Toggle(_TRIPLANAR_NOISE_TRANSITION_ON)]_TriplanarNoiseTransitionOn("Noise Transition", Float) = 0 + [EffectProperty(ParentEffect# TRIPLANAR_MAPPING, Keywords(_TRIPLANAR_NOISE_TRANSITION_ON), AllowReset# True)] _TriplanarNoiseTex("Noise Tex", 2D) = "white" {} + [EffectProperty(ParentEffect# TRIPLANAR_MAPPING, Keywords(_TRIPLANAR_NOISE_TRANSITION_ON), AllowReset# True)] _TriplanarTransitionPower("Transition Power", Range(0, 1.0)) = 0.75 + + //Texture Blending + [Effect(EffectID# TEXTURE_BLENDING, GroupID# ColorEffects, CustomDrawer# TEXTURE_BLENDING_EFFECT_DRAWER)][Toggle(_TEXTURE_BLENDING_ON)]_TextureBlending ("Texture Blending", Float) = 0 + [EffectProperty(TEXTURE_BLENDING)][KeywordEnum(VertexColor, Texture)]_TextureBlendingSource("Source", Float) = 0 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE), AllowReset# True)]_TexBlendingMask("Texture Blending Mask", 2D) = "white" {} + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffG("Cutoff (G)", Range(0, 1)) = 0.1 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessG("Smoothness (G)", Range(0, 1)) = 0.4 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffB("Cutoff (B)", Range(0, 1)) = 0.1 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessB("Smoothness (B)", Range(0, 1)) = 0.4 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskCutoffWhite("Cutoff (White)", Range(0, 1)) = 0.15 + [EffectProperty(ParentEffect# TEXTURE_BLENDING, Keywords(_TEXTUREBLENDINGSOURCE_TEXTURE, _TEXTUREBLENDINGSOURCE_VERTEXCOLOR), AllowReset# True)]_BlendingMaskSmoothnessWhite("Smoothness (White)", Range(0, 1)) = 0.4 + [EffectProperty(TEXTURE_BLENDING)][KeywordEnum(RGB, BlackAndWhite)]_TextureBlendingMode("Blending Mode", Float) = 0 + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureG("Blending Texture (G)", 2D) = "white" {} + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureB("Blending Texture (B)", 2D) = "white" {} + [EffectProperty(TEXTURE_BLENDING)]_BlendingTextureWhite("Blending Texture (White)", 2D) = "white" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapG("Blending Normal Map (G)", 2D) = "bump" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapB("Blending Normal Map (B)", 2D) = "bump" {} + [NoScaleOffset][EffectProperty(TEXTURE_BLENDING)]_BlendingNormalMapWhite("Blending Normal Map (White)", 2D) = "bump" {} + + //Depth Coloring + [Effect(EffectID# DEPTH_COLORING, GroupID# ColorEffects)][Toggle(_DEPTH_COLORING_ON)]_DepthColoringOn("Depth Coloring", Float) = 0 + + //Sub surface scattering + [Effect(EffectID# SUBSURFACE_SCATTERING, GroupID# ColorEffects)][Toggle(_SUBSURFACE_SCATTERING_ON)]_SubsurfaceScattering("Fake Subsurface Scattering", Float) = 0.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_NormalInfluence("Normal Influence", Range(0, 2.5)) = 0.5 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSPower("SSS Power", Range(0.01, 20)) = 1.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSFrontPower("SSS Front Power", Range(0.2, 20)) = 3.0 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSFrontAtten("SSS Front Atten", Range(0, 1)) = 0.3 + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSAtten("SSS General Atten", Range(0, 1)) = 1.0 + [EffectProperty(SUBSURFACE_SCATTERING)][HDR]_SSSColor("SSS Color", Color) = (1.0, 1.0, 1.0, 1.0) + [EffectProperty(SUBSURFACE_SCATTERING)]_SSSMap("SSS Map", 2D) = "white" {} + + //Alpha Cutoff + [Effect(EffectID# ALPHA_CUTOFF, GroupID# AlphaEffects)][Toggle(_ALPHA_CUTOFF_ON)]_AlphaCutoffOn("Alpha Cutoff", Float) = 1.0 + [EffectProperty(ALPHA_CUTOFF)]_AlphaCutoffValue("Cutoff Value", Range(0, 1)) = 0.25 + + //Fade + [Effect(EffectID# FADE, GroupID# AlphaEffects)][Toggle(_FADE_ON)]_FadeOn("Fade", Float) = 0 + [EffectProperty(FADE)]_FadeTex("Fade Tex", 2D) = "white" {} + [EffectProperty(FADE)][KeywordEnum(UV1, UV2, WORLD_SPACE)]_FadeUVSet("UV Set", Float) = 0 + [EffectProperty(FADE)]_FadeAmount("Fade Amount", Range(0, 1)) = 0.0 + [EffectProperty(FADE)]_FadePower("Fade Power", Range(0.25, 4.0)) = 1.0 + [EffectProperty(FADE)]_FadeTransition("Fade Transition", Range(0, 0.4)) = 0.2 + [EffectProperty(FADE)][Toggle(_FADE_BURN_ON)]_FadeBurnOn("Use Fade Burn Color?", Float) = 0.0 + [EffectProperty(ParentEffect# FADE, Keywords(_FADE_BURN_ON), AllowReset# True)][HDR]_FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) + [EffectProperty(ParentEffect# FADE, Keywords(_FADE_BURN_ON), AllowReset# True)]_FadeBurnWidth("Fade Burn Width", Range(0, 0.2)) = 0.01 + + //Intersection Fade + [Effect(EffectID# INTERSECTION_FADE, GroupID# AlphaEffects)][Toggle(_INTERSECTION_FADE_ON)]_IntersectionFadeOn("Intersection Fade", Float) = 0.0 + [EffectProperty(INTERSECTION_FADE)]_IntersectionFadeFactor("Intersection Fade Factor", Range(0.1, 3.0)) = 1.0 + + //Alpha Round + [Effect(EffectID# ALPHA_ROUND, GroupID# AlphaEffects)][Toggle(_ALPHA_ROUND_ON)]_AlphaRoundOn("Alpha Round", Float) = 0 + + //Fade By Cam Distance + [Effect(EffectID# FADE_BY_CAM_DISTANCE, GroupID# AlphaEffects)][Toggle(_FADE_BY_CAM_DISTANCE_ON)]_FadeByCamDistanceOn("Fade By Cam Distance", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)][Toggle(_FADE_BY_CAM_DISTANCE_NEAR_FADE)]_NearFade("Near Fade", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)]_MinDistanceToFade("Min Distance", Float) = 0 + [EffectProperty(FADE_BY_CAM_DISTANCE)]_MaxDistanceToFade("Max Distance", Float) = 100 + + //Dither + [Effect(EffectID# DITHER, GroupID# AlphaEffects)][Toggle(_DITHER_ON)]_DitherOn("Dither", Float) = 0 + [EffectProperty(DITHER)]_DitherScale("Scale", Range(0.01, 2)) = 1 + + // + [Effect(EffectID# OUTLINETYPE, GroupID# OtherEffects, ExtraPasses# (OUTLINE))][KeywordEnum(None, Simple, Constant, FadeWithDistance)]_OutlineType("Outline Type", Float) = 0 + + // + [PerRendererData]_TimingSeed("Timing Seed", Float) = 0 + + + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)][HDR]_OutlineColor("Outline Color", Color) = (0, 0, 0, 1) + [EffectProperty(OUTLINETYPE, CONSTANT)]_MaxCameraDistance("Max Camera Distance", Float) = 1000 + [EffectProperty(OUTLINETYPE, FADEWITHDISTANCE)]_MaxFadeDistance("Max Fade Distance", Float) = 250 + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)]_OutlineThickness("Outline Thickness", Float) = 1 + [EffectProperty(OUTLINETYPE, SIMPLE, CONSTANT, FADEWITHDISTANCE)][Enum(Basic, 8, Clean, 6)]_OutlineMode("Outline Mode", Float) = 8 + [IntRange]_StencilRef("Stencil Reference Value", Range(1, 255)) = 1 + } + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "12.0" + } + + Pass + { + Name "AllIn13D_MainPass_URP" + Tags + { + "RenderType" = "Opaque" + "RenderPipeline" = "UniversalPipeline" + } + + Blend [_BlendSrc] [_BlendDst] + Cull [_CullingMode] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + ColorMask [_ColorMask] + + /**/ + + HLSLPROGRAM + #define URP_PASS + #define ALLIN1_FORWARD_PASS + + #pragma vertex BasicVertex + #pragma fragment BasicFragment + + + #if UNITY_VERSION >= 60000000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #endif + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #if defined(LOD_FADE_CROSSFADE) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + #endif + + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_BasePass.hlsl" + + ENDHLSL + } + + Pass + { + Name "DepthOnly" + Tags + { + "LightMode" = "DepthOnly" + } + + // ------------------------------------- + // Render State Commands + ZWrite On + ColorMask R + Cull[_CullingMode] + + HLSLPROGRAM + #define ALLIN1_DEPTH_ONLY_PASS + + // ------------------------------------- + // Shader Stages + #pragma vertex DepthOnlyVertex + #pragma fragment DepthOnlyFragment + + #define URP_PASS + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + // ------------------------------------- + // Includes + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl" + ENDHLSL + } + + Pass + { + Name "DepthNormals" + Tags + { + "LightMode" = "DepthNormals" + } + + ZWrite On + Cull[_CullingMode] + + HLSLPROGRAM + #define ALLIN1_DEPTH_NORMALS_PASS + + // Shader Stages + #pragma vertex DepthNormalsVertex + #pragma fragment DepthNormalsFragment + + #define URP_PASS + + #if UNITY_VERSION >= 60000000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #endif + + #include "../ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl" + + //Includes + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_URP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl" + + ENDHLSL + } + + Pass + { + Name "Meta" + Tags{ "LightMode" = "Meta" } + + Cull Off + + HLSLPROGRAM + #pragma exclude_renderers gles gles3 glcore + #define URP_PASS + + #pragma vertex AllIn1VertexMeta + #pragma fragment AllIn1FragmentMeta + #pragma shader_feature EDITOR_VISUALIZATION + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + + #include "../ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl" + + ENDHLSL + } + } + + SubShader + { + Pass + { + Name "AllIn13D_Forward_BIRP" + Tags { "LightMode" = "ForwardBase" } + + + /**/ + + + Blend [_BlendSrc] [_BlendDst] + Cull [_CullingMode] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + ColorMask [_ColorMask] + + HLSLPROGRAM + #pragma target 3.0 + #pragma multi_compile_fwdbase + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #define BIRP_PASS + #define BUILTIN_MAIN_PASS + + #pragma vertex BasicVertex + #pragma fragment BasicFragment + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShader_BasePass.hlsl" + + ENDHLSL + } + + Pass + { + Name "FORWARD_DELTA" + Tags { "LightMode" = "ForwardAdd"} + + Blend One One + ZWrite Off + ZTest LEqual + Cull [_CullingMode] + + HLSLPROGRAM + #pragma target 3.0 + + #define BIRP_PASS + #define FORWARD_ADD_PASS + + #pragma multi_compile_fwdadd_fullshadows + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + + #pragma vertex BasicVertex + #pragma fragment BasicFragmentAdd + + #include "UnityCG.cginc" + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_Features.hlsl" + #include "AutoLight.cginc" + #include "UnityLightingCommon.cginc" + #include "../ShaderLibrary/AllIn13DShader_CommonStructs.hlsl" + #include "../ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl" + #include "../ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLight.hlsl" + #include "../ShaderLibrary/AllIn13DShader_UVEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_VertexEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl" + #include "../ShaderLibrary/AllIn13DShaderCore.hlsl" + #include "../ShaderLibrary/AllIn13DShaderLightAddPass.hlsl" + + ENDHLSL + } + } + + CustomEditor "AllIn13DShader.AllIn13DShaderMaterialInspector" +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader_NoShadowCaster.shader.meta b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader_NoShadowCaster.shader.meta new file mode 100644 index 0000000..52cd642 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader_NoShadowCaster.shader.meta @@ -0,0 +1,17 @@ +fileFormatVersion: 2 +guid: 3bc39c06ce1e4fb44bc21dcf24dde7fe +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/Generic Shaders/AllIn13DShader_NoShadowCaster.shader + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary.meta new file mode 100644 index 0000000..722a835 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ff59db4f579c1c849b7ac4e48f2df8c2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderCore.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderCore.hlsl new file mode 100644 index 0000000..9759ed5 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderCore.hlsl @@ -0,0 +1,558 @@ +#ifndef ALLIN13DSHADER_CORE_INCLUDED +#define ALLIN13DSHADER_CORE_INCLUDED + +float4 GetBaseColor(EffectsData data) +{ + float4 res = float4(0, 0, 0, 1); + +#ifdef _TRIPLANAR_MAPPING_ON + float4 colFront = 0; + float4 colSide = 0; + float4 colTop = 0; + float4 colDown = 0; + + #ifdef _STOCHASTIC_SAMPLING_ON + float2 dx = 0; + float2 dy = 0; + + float stochasticScale = ACCESS_PROP_FLOAT(_StochasticScale); + float stochasticSkew = ACCESS_PROP_FLOAT(_StochasticSkew); + float4x3 stochasticOffsets_front = getStochasticOffsets(UV_FRONT(data), stochasticScale, stochasticSkew); + STOCHASTIC_SAMPLING_NO_DEF_DD(_MainTex, UV_FRONT(data), stochasticOffsets_front, colFront) + + float4x3 stochasticOffsets_side = getStochasticOffsets(UV_SIDE(data), stochasticScale, stochasticSkew); + STOCHASTIC_SAMPLING_NO_DEF_DD(_MainTex, UV_SIDE(data), stochasticOffsets_side, colSide) + + float4x3 stochasticOffsets_top = getStochasticOffsets(UV_TOP(data), stochasticScale, stochasticSkew); + STOCHASTIC_SAMPLING_NO_DEF_DD(_TriplanarTopTex, UV_TOP(data), stochasticOffsets_top, colTop) + + float4x3 stochasticOffsets_down = getStochasticOffsets(UV_DOWN(data), stochasticScale, stochasticSkew); + STOCHASTIC_SAMPLING_NO_DEF_DD(_MainTex, UV_DOWN(data), stochasticOffsets_down, colDown) + #else + colFront = SAMPLE_TEX2D(_MainTex, UV_FRONT(data)); + colSide = SAMPLE_TEX2D(_MainTex, UV_SIDE(data)); + + colTop = SAMPLE_TEX2D(_TriplanarTopTex, UV_TOP(data)); + colDown = SAMPLE_TEX2D(_MainTex, UV_DOWN(data)); + #endif + + float faceDown = smoothstep(ACCESS_PROP_FLOAT(_FaceDownCutoff), 1.0, UV_DOWN_WEIGHT(data)); + colTop = lerp(colTop, colDown, faceDown); + + colFront *= UV_FRONT_WEIGHT(data); + colSide *= UV_SIDE_WEIGHT(data); + colTop *= UV_TOP_WEIGHT(data); + + res = colFront + colSide + colTop; +#else + #ifdef _STOCHASTIC_SAMPLING_ON + float4x3 stochasticOffsets = getStochasticOffsets(MAIN_UV(data), ACCESS_PROP_FLOAT(_StochasticScale), ACCESS_PROP_FLOAT(_StochasticSkew)); + STOCHASTIC_SAMPLING(_MainTex, MAIN_UV(data), stochasticOffsets, res) + #else + res = SAMPLE_TEX2D(_MainTex, MAIN_UV(data)); + #endif +#endif + + return res; +} + +float3 GetNormalWS(EffectsData data, FragmentData i, AllIn1DecalData decalData) +{ + float3 res = data.normalWS; + +#ifdef _STOCHASTIC_SAMPLING_ON + float4x3 stochasticOffset = 0; + float2 dx = 0; + float2 dy = 0; +#endif + +#ifdef _NORMAL_MAP_ON + #ifdef _TRIPLANAR_MAPPING_ON + #ifdef _TRIPLANARNORMALSPACE_LOCAL + float3 normalReference = data.normalOS; + #else + float3 normalReference = data.normalWS; + #endif + + float4 sampledNormal_side = 0; + float4 sampledNormal_top = 0; + float4 sampledNormal_front = 0; + float4 sampledNormal_down = 0; + + #ifdef _STOCHASTIC_SAMPLING_ON + float stochasticScale = ACCESS_PROP_FLOAT(_StochasticScale); + float stochasticSkew = ACCESS_PROP_FLOAT(_StochasticSkew); + float4x3 stochasticOffsets_side = getStochasticOffsets(NORMAL_UV_SIDE(data), stochasticScale, stochasticSkew); + STOCHASTIC_SAMPLING_NO_DEF_DD(_NormalMap, NORMAL_UV_SIDE(data), stochasticOffsets_side, sampledNormal_side) + + float4x3 stochasticOffsets_top = getStochasticOffsets(NORMAL_UV_TOP(data), stochasticScale, stochasticSkew); + STOCHASTIC_SAMPLING_NO_DEF_DD(_TriplanarTopNormalMap, NORMAL_UV_TOP(data), stochasticOffsets_top, sampledNormal_top) + + float4x3 stochasticOffsets_front = getStochasticOffsets(NORMAL_UV_FRONT(data), stochasticScale, stochasticSkew); + STOCHASTIC_SAMPLING_NO_DEF_DD(_NormalMap, NORMAL_UV_FRONT(data), stochasticOffsets_front, sampledNormal_front) + #else + sampledNormal_side = SAMPLE_TEX2D(_NormalMap, NORMAL_UV_SIDE(data)); + sampledNormal_top = SAMPLE_TEX2D(_TriplanarTopNormalMap, NORMAL_UV_TOP(data)); + sampledNormal_front = SAMPLE_TEX2D(_NormalMap, NORMAL_UV_FRONT(data)); + sampledNormal_down = SAMPLE_TEX2D(_NormalMap, UV_DOWN(data)); + #endif + + float faceDown = smoothstep(ACCESS_PROP_FLOAT(_FaceDownCutoff), 1.0, UV_DOWN_WEIGHT(data)); + sampledNormal_top = lerp(sampledNormal_top, sampledNormal_down, faceDown); + float tNormalYWeight = lerp(ACCESS_PROP_FLOAT(_TopNormalStrength), ACCESS_PROP_FLOAT(_NormalStrength), faceDown); + + float3 tnormalX = UnpackNormal(sampledNormal_side); + tnormalX.xy *= ACCESS_PROP_FLOAT(_NormalStrength); + + float3 tnormalY = UnpackNormal(sampledNormal_top); + tnormalY.xy *= tNormalYWeight; + + float3 tnormalZ = UnpackNormal(sampledNormal_front); + tnormalZ.xy *= ACCESS_PROP_FLOAT(_NormalStrength); + + tnormalX = float3(tnormalX.xy + normalReference.zy, normalReference.x); + tnormalY = float3(tnormalY.xy + normalReference.xz, normalReference.y); + tnormalZ = float3(tnormalZ.xy + normalReference.xy, normalReference.z); + + res = normalize( + tnormalX.zyx * UV_SIDE_WEIGHT(data) + + tnormalY.xzy * UV_TOP_WEIGHT(data) + + tnormalZ.xyz * UV_FRONT_WEIGHT(data) + ); + + #ifdef ALLIN1_DECALS_READY_TO_USE + res = lerp(decalData.normalTS, res, decalData.mask); + #endif + + #else + + float4 sampledNormal = 0; + #ifdef _STOCHASTIC_SAMPLING_ON + float4x3 stochasticOffsets = getStochasticOffsets(MAIN_UV(data), ACCESS_PROP_FLOAT(_StochasticScale), ACCESS_PROP_FLOAT(_StochasticSkew)); + STOCHASTIC_SAMPLING_NO_DEF_DD(_NormalMap, MAIN_UV(data), stochasticOffsets, sampledNormal) + #else + sampledNormal = SAMPLE_TEX2D(_NormalMap, MAIN_UV(data)); + #endif + + float3 tnormal = UnpackNormal(sampledNormal); + tnormal.xy *= ACCESS_PROP_FLOAT(_NormalStrength); + + #if defined(ALLIN1_DECALS_READY_TO_USE) && defined(ALLIN1_DECAL_MODE_SCREEN_SPACE) + tnormal = BlendingUnpackedNormals(tnormal, decalData.unpackedNormal); + #endif + + res.x = dot(i.tspace0, tnormal); + res.y = dot(i.tspace1, tnormal); + res.z = dot(i.tspace2, tnormal); + + #if defined(ALLIN1_DECALS_READY_TO_USE) && defined(ALLIN1_DECAL_MODE_DBUFFER) + res = lerp(decalData.normalTS, res, decalData.mask); + #endif + + res = normalize(res); + #endif + + #if defined(_TEXTURE_BLENDING_ON) + + #ifdef _TEXTUREBLENDINGSOURCE_TEXTURE + float3 maskColor = SAMPLE_TEX2D(_TexBlendingMask, /*data.mainUV*/MAIN_UV(data)).rgb; + #else + float3 maskColor = data.vertexColor.rgb; + #endif + + #ifdef _TEXTUREBLENDINGMODE_RGB + float2 texGUV = SIMPLE_CUSTOM_TRANSFORM_TEX(data.rawMainUV, _BlendingTextureG); + float2 texBUV = SIMPLE_CUSTOM_TRANSFORM_TEX(data.rawMainUV, _BlendingTextureB); + + float4 sampledNormalG = 0; + float4 sampledNormalB = 0; + #ifdef _STOCHASTIC_SAMPLING_ON + STOCHASTIC_SAMPLING_COMPLETE_NO_DEF_DD(_BlendingNormalMapG, texGUV, stochasticOffset, sampledNormalG) + STOCHASTIC_SAMPLING_COMPLETE_NO_DEF_DD(_BlendingNormalMapB, texBUV, stochasticOffset, sampledNormalB) + #else + sampledNormalG = SAMPLE_TEX2D(_BlendingNormalMapG, texGUV); + sampledNormalB = SAMPLE_TEX2D(_BlendingNormalMapB, texBUV); + #endif + + float3 tnormalG = UnpackNormal(sampledNormalG); + float3 tnormalB = UnpackNormal(sampledNormalB); + + float3 normalG = GetNormalWSFromNormalMap( + tnormalG, ACCESS_PROP_FLOAT(_NormalStrength), + i.tspace0, i.tspace1, i.tspace2); + + float3 normalB = GetNormalWSFromNormalMap( + tnormalB, ACCESS_PROP_FLOAT(_NormalStrength), + i.tspace0, i.tspace1, i.tspace2); + + res = normalize(lerp(res, normalG, maskColor.g)); + res = normalize(lerp(res, normalB, maskColor.b)); + #else + float2 texWhiteUV = SIMPLE_CUSTOM_TRANSFORM_TEX(data.rawMainUV, _BlendingTextureWhite); + + float4 sampledNormalWhite = 0; + #ifdef _STOCHASTIC_SAMPLING_ON + STOCHASTIC_SAMPLING_COMPLETE_NO_DEF_DD(_BlendingNormalMapWhite, texWhiteUV, stochasticOffset, sampledNormalWhite) + #else + sampledNormalWhite = SAMPLE_TEX2D(_BlendingNormalMapWhite, texWhiteUV); + #endif + + float3 tnormalWhite = UnpackNormal(sampledNormalWhite); + float3 normalWhite = GetNormalWSFromNormalMap( + tnormalWhite, ACCESS_PROP_FLOAT(_NormalStrength), + i.tspace0, i.tspace1, i.tspace2); + float maskLuminosity = GetLuminanceRaw(float4(maskColor.rgb, 1.0)); + maskLuminosity = saturate(maskLuminosity); + res = lerp(res, normalWhite, maskLuminosity); + #endif + #endif +#endif + + + + + return res; +} + +#if defined(_FLAT_NORMALS_ON) +float3 GetFlatNormalWS(float3 originalNormal, float3 positionWS) +{ + float3 res = originalNormal; + float3 worldPosDDX = ddx(positionWS); + float3 worldPosDDY = ddy(positionWS); + + float3 flatNormal = normalize(cross(worldPosDDY, worldPosDDX)); + + float3 blendedNormal = lerp(originalNormal, flatNormal, ACCESS_PROP_FLOAT(_FlatNormalsBlend)); + blendedNormal = normalize(blendedNormal); + res = blendedNormal; + + return res; +} +#endif + + +EffectsData CalculateEffectsData_ShadowCaster(FragmentDataShadowCaster i) +{ + EffectsData res; + + INIT_EFFECTS_DATA(res) + + res.vertexColor = 1.0; + res.mainUV = SCALED_MAIN_UV(i); + res.rawMainUV = i.uv2; + res.shaderTime = i.shaderTime; + + res.uvMatrix = 0; + res.uvMatrix._m00_m01 = i.mainUV.xy; + res.normalOS = normalize(i.normalOS); + res.normalWS = normalize(i.normalWS); + + res.vertexOS = i.positionOS; + res.vertexWS = i.positionWS; + + return res; +} + +EffectsData CalculateEffectsData(FragmentData i, AllIn1DecalData decalData) +{ + EffectsData res; + + res.vertexColor = float4( + VERTEX_COLOR_R(i), + VERTEX_COLOR_G(i), + VERTEX_COLOR_B(i), + VERTEX_COLOR_A(i)); + + res.normalizedScreenSpaceUV = float2(0, 0); +#ifdef URP_PASS + res.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(i.pos); +#endif + + res.vertexColorLuminosity = GetLuminanceRaw(float4(res.vertexColor.r, res.vertexColor.g, res.vertexColor.b, 1.0)); + res.vertexColorLuminosity = saturate(res.vertexColorLuminosity); + + res.mainUV = SCALED_MAIN_UV(i); + res.rawMainUV = RAW_MAIN_UV(i); + + res.vertexOS = POSITION_OS(i); + res.vertexWS = POSITION_WS(i); + res.vertexVS = mul(UNITY_MATRIX_MV, float4(res.vertexOS, 1.0)).xyz; + + res.normalOS = normalize(NORMAL_OS(i)); + res.normalWS = normalize(i.normalWS); + res.viewDirWS = normalize(VIEWDIR_WS(i)); + + res.tangentWS = 0; + res.bitangentWS = 0; +#ifdef REQUIRE_TANGENT_WS + res.tangentWS = normalize(TANGENT_WS(i)); + res.bitangentWS = normalize(cross(res.normalWS.xyz, res.tangentWS.xyz)); +#endif + +#ifdef _NORMAL_MAP_ON + res.uv_normalMap = UV_NORMAL_MAP(i); +#endif + + res.lightColor = GetMainLightColorRGB(); + res.lightDir = GetMainLightDir(POSITION_WS(i)); + + res.projPos = 0; + res.sceneDepthDiff = 0; + res.normalizedDepth = 0; +#ifdef REQUIRE_SCENE_DEPTH + res.projPos = i.projPos; + res.sceneDepthDiff = GetSceneDepthDiff(i.projPos); + res.normalizedDepth = GetNormalizedDepth(i.projPos); +#endif + + res.pos = i.pos; + + res.camDistance = 0; +#ifdef REQUIRE_CAM_DISTANCE + float3 positionVS = mul(UNITY_MATRIX_V, float4(POSITION_WS(i), 1.0)).xyz; + res.camDistanceViewSpace = -positionVS.z; + res.camDistance = distance(POSITION_WS(i), _WorldSpaceCameraPos); +#endif + +#ifdef _UV_DISTORTION_ON + res.uv_dist = SIMPLE_CUSTOM_TRANSFORM_TEX(i.mainUV.xy, _DistortTex); +#endif + + res.shaderTime = SHADER_TIME(i); + + res.uvMatrix = 0; + res.uvMatrix._m00_m01 = i.mainUV.xy; + +#ifdef _NORMAL_MAP_ON + res.uv_matrix_normalMap = 0; + MAIN_NORMAL_UV(res) = UV_NORMAL_MAP(i); +#endif + + res.uvDiff = UV_DIFF(i); + + res._ShadowCoord = i._ShadowCoord; + +#ifdef HAS_PBR_PROPERTIES + res.metallic = ACCESS_PROP_FLOAT(_Metallic) * decalData.MAOSAlpha + decalData.metallic; + res.smoothness = ACCESS_PROP_FLOAT(_Smoothness) * decalData.MAOSAlpha + decalData.smoothness; +#endif + + return res; +} + + +float2 ApplyUVEffects_VertexStage(float2 inputUV, float3 vertexWS, float4 projPos, float3 shaderTime) +{ + float2 res = inputUV; + +#ifdef _SCREEN_SPACE_UV_ON + res = ScreenSpaceUV(res, vertexWS, projPos); +#endif + +#ifdef _SCROLL_TEXTURE_ON + res = ScrollTexture(res, shaderTime); +#endif + +#ifdef _HAND_DRAWN_ON + res = HandDrawn(res, shaderTime); +#endif + + return res; +} + +EffectsData ApplyUVEffects_FragmentStage(EffectsData data) +{ + EffectsData res = data; + +#ifdef _TRIPLANAR_MAPPING_ON + res = TriplanarMapping(res); +#endif + +#ifdef _WAVE_UV_ON + res = WaveUV(res); +#endif + +#ifdef _UV_DISTORTION_ON + res = UVDistortion(res); +#endif + +#ifdef _PIXELATE_ON + res = Pixelate(res); +#endif + + return res; +} + +float4 ApplyVertexEffects(float4 vertexOS, float3 normalOS, float3 shaderTime) +{ + float4 res = vertexOS; + +#ifdef _VERTEX_SHAKE_ON + res.xyz = VertexShake(res.xyz, shaderTime); +#endif + +#ifdef _VERTEX_INFLATE_ON + res.xyz = VertexInflate(res.xyz, normalOS, shaderTime); +#endif + +#ifdef _VERTEX_DISTORTION_ON + res.xyz = VertexDistortion(res.xyz, normalOS, shaderTime); +#endif + +#ifdef _VOXELIZE_ON + res.xyz = VertexVoxel(res.xyz); +#endif + +#ifdef _GLITCH_ON + res.xyz = Glitch(res.xyz, shaderTime); +#endif + +#ifdef _WIND_ON + res.xyz = Wind(res.xyz, shaderTime); +#endif + + return res; +} + +float4 ApplyColorEffectsBeforeLighting(float4 inputColor, EffectsData data) +{ + float4 res = inputColor; + +#ifdef _ALBEDO_VERTEX_COLOR_ON + res = AlbedoVertexColor(res, data); +#endif + +#ifdef _TEXTURE_BLENDING_ON + res = TextureBlending(res, data); +#endif + +#ifdef _HOLOGRAM_ON + res = Hologram(res, data); +#endif + +#ifdef _HEIGHT_GRADIENT_ON + res = HeightGradient(res, data); +#endif + +#ifdef _HUE_SHIFT_ON + res.rgb = HueShift(res.rgb); +#endif + +#ifdef _MATCAP_ON + float3 matcap = Matcap(data); + + #ifdef _MATCAPBLENDMODE_MULTIPLY + float3 colorWithMatcapApplied = res.rgb * matcap; + #else + float3 colorWithMatcapApplied = matcap; + #endif + + res.rgb = lerp(res.rgb, colorWithMatcapApplied, ACCESS_PROP_FLOAT(_MatcapBlend)); +#endif + +#ifdef _POSTERIZE_ON + res.rgb = Posterize(res.rgb); +#endif + +#ifdef _CONTRAST_BRIGHTNESS_ON + res.rgb = ContrastBrightness(res.rgb); +#endif + +#if defined(_GREYSCALE_ON) && defined(_GREYSCALESTAGE_BEFORELIGHTING) + res.rgb = Greyscale(res.rgb); +#endif + +#if defined(_RIM_LIGHTING_ON) && defined(_RIMLIGHTINGSTAGE_BEFORELIGHTING) + res.rgb = Rim(res.rgb, data); +#endif + +#if defined(_COLOR_RAMP_ON) && defined(_COLORRAMPLIGHTINGSTAGE_BEFORELIGHTING) + res = ColorRamp(res, data); +#endif + +#if defined(_RIM_LIGHTING_ON) && defined(_RIMLIGHTINGSTAGE_BEFORELIGHTINGLAST) + res.rgb = Rim(res.rgb, data); +#endif + + return res; +} + +float4 ApplyColorEffectsAfterLighting(float4 inputColor, EffectsData data) +{ + float4 res = inputColor; + +#ifdef _SUBSURFACE_SCATTERING_ON + res = SubsurfaceScattering(inputColor, data); +#endif + +#ifdef _HIT_ON + res = Hit(res); +#endif + +#ifdef _HIGHLIGHTS_ON + res.rgb = Highlights(res.rgb, data); +#endif + +#if defined(_DEPTH_COLORING_ON) + res = DepthColoring(res, data); +#endif + +#if defined(_RIM_LIGHTING_ON) && defined(_RIMLIGHTINGSTAGE_AFTERLIGHTING) + res.rgb = Rim(res.rgb, data); +#endif + +#if defined(_GREYSCALE_ON) && !defined(_GREYSCALESTAGE_BEFORELIGHTING) + res.rgb = Greyscale(res.rgb); +#endif + +#ifdef _INTERSECTION_GLOW_ON + res.rgb = IntersectionGlow(res, data).rgb; +#endif + +#if defined(_COLOR_RAMP_ON) && !defined(_COLORRAMPLIGHTINGSTAGE_BEFORELIGHTING) + res = ColorRamp(res, data); +#endif + + return res; +} + +float4 ApplyAlphaEffects(float4 inputColor, + float2 uv, float2 uv2, float3 worldPos, + float sceneDepthDiff, float camDistance, float4 screenPos) +{ + float4 res = inputColor; + +#ifdef _FADE_ON + float2 selectedUV; + #if defined(_FADEUVSET_UV1) + selectedUV = uv; + #elif defined(_FADEUVSET_UV2) + selectedUV = uv2; + #else + selectedUV = worldPos.xy; + #endif + + res = Fade(res, selectedUV); + #endif +#endif + +#ifdef _INTERSECTION_FADE_ON + res = IntersectionFade(res, sceneDepthDiff); +#endif + +#ifdef _ALPHA_ROUND_ON + res.a = round(res.a); +#endif + + float camFadeDistanceNormalized = 1.0; +#ifdef _FADE_BY_CAM_DISTANCE_ON + res = FadeByCamDistance(res, camDistance, camFadeDistanceNormalized); +#endif + +#if defined(_DITHER_ON) && !defined(SHADOW_CASTER_PASS) + res = Dither_float4(res, screenPos, camFadeDistanceNormalized); +#endif + + return res; +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderCore.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderCore.hlsl.meta new file mode 100644 index 0000000..d31ae54 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderCore.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 2dc05823453a1374da5366de267bb792 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderCore.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl new file mode 100644 index 0000000..9ab5ef7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl @@ -0,0 +1,445 @@ +#ifndef ALLIN13DSHADER_HELPER_BIRP_INCLUDED +#define ALLIN13DSHADER_HELPER_BIRP_INCLUDED + +#include "AutoLight.cginc" + +#define OBJECT_TO_WORLD_MATRIX unity_ObjectToWorld + +//#if !defined(LIGHTMAP_ON) && defined(SHADOWS_SCREEN) +// #if defined(SHADOWS_SHADOWMASK) && !defined(UNITY_NO_SCREENSPACE_SHADOWS) +// #define ADDITIONAL_MASKED_DIRECTIONAL_SHADOWS 1 +// #endif +//#endif + +#ifdef REQUIRE_SCENE_DEPTH + + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + + float GetRawDepth(float4 projPos) + { + //float res = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(projPos)); + float res = tex2Dproj(_CameraDepthTexture, projPos); + return res; + } + + float GetLinearDepth01(float4 projPos) + { + float rawDepth = GetRawDepth(projPos); + float res = Linear01Depth (rawDepth); + + return res; + } + + float GetSceneDepthDiff(float4 projPos) + { + float rawDepth = GetRawDepth(projPos); + float res = LinearEyeDepth(rawDepth) - projPos.z; + return res; + } + +#endif + +float3 GetNormalWS(float3 normalOS) +{ + float3 normalWS = UnityObjectToWorldNormal(normalOS); + return normalWS; +} + +float3 GetViewDirWS(float3 vertexWS) +{ + float3 res = UnityWorldSpaceViewDir(vertexWS); + return res; +} + +float3 GetPositionVS(float3 positionOS) +{ + float3 res = UnityObjectToViewPos(positionOS); + return res; +} + +float3 GetPositionWS(float4 positionOS) +{ + return mul(unity_ObjectToWorld, positionOS).xyz; +} + +float3 GetPositionOS(float4 positionWS) +{ + return mul(unity_WorldToObject, positionWS); +} + +float3 GetDirWS(float4 dirOS) +{ + return mul(unity_ObjectToWorld, float4(dirOS.xyz, 0)); +} + +float3 GetDirOSFloat3(float3 dirOS) +{ + return mul(unity_WorldToObject, float4(dirOS.xyz, 0)); +} + +float3 GetDirOS(float4 dirOS) +{ + return mul(unity_WorldToObject, dirOS); +} + +float3 GetMainLightDir(float3 vertexWS) +{ +#ifdef _LIGHTMODEL_FASTLIGHTING + float3 mainLightDir = global_lightDirection; +#else + float3 mainLightDir = normalize(_WorldSpaceLightPos0.xyz - vertexWS * _WorldSpaceLightPos0.w); +#endif + + return mainLightDir; +} + +float3 GetMainLightColorRGB() +{ +#ifdef _LIGHTMODEL_FASTLIGHTING + float3 res = global_lightColor.rgb; +#else + float3 res = _LightColor0.rgb; +#endif + + return res; +} + +float2 GetSSAO(float2 normalizedScreenSpaceUV, float alpha) +{ + float2 res = float2(1, 1); + return res; +} + +float FadeShadows (float3 worldPos, float shadowAtten, AllIn1GI gi) +{ + float res = shadowAtten; +#if defined(SHADOWS_SHADOWMASK) + float bakedAttenuation = UnitySampleBakedOcclusion(gi.uvLightmap, worldPos); + float zDist = dot(_WorldSpaceCameraPos.xyz - worldPos, UNITY_MATRIX_V[2].xyz); + float shadowFadeDistance = UnityComputeShadowFadeDistance(worldPos, zDist); + float shadowFade = UnityComputeShadowFade(shadowFadeDistance); + + res = UnityMixRealtimeAndBakedShadows(shadowAtten, bakedAttenuation, shadowFade); +#endif + + return res; +} + +float GetShadowAttenuation(EffectsData effectsData, AllIn1GI gi) +{ + float res = 1; + +#if !defined(_LIGHTMODEL_FASTLIGHTING) + UNITY_LIGHT_ATTENUATION(attenuation, effectsData, effectsData.vertexWS); + #if !defined(FORWARD_ADD_PASS) + attenuation = FadeShadows(effectsData.vertexWS, attenuation, gi); + #endif + + res = attenuation; +#endif + + return res; +} + +AllIn1LightData GetPointLightData(float3 vertexWS, float3 normalWS, float3 lightPositionWS, float3 lightColor, float pointLightAtten, EffectsData effectsData, AllIn1GI gi) +{ + AllIn1LightData lightData; + + float3 lightVec = lightPositionWS - vertexWS; + float3 lightDir = normalize(lightVec); + + float atten = 1 / (1 + dot(lightVec, lightVec) * pointLightAtten); + + lightData.lightColor = lightColor; + lightData.lightDir = lightDir; + +#ifdef _RECEIVE_SHADOWS_ON + lightData.realtimeShadow = GetShadowAttenuation(effectsData, gi); +#else + lightData.realtimeShadow = 1.0; +#endif + lightData.distanceAttenuation = atten; + + lightData.shadowColor = /*lerp(0, 1.0, lightData.realtimeShadow * lightData.distanceAttenuation)*/lightData.realtimeShadow; + lightData.layerMask = 1.0; + + return lightData; +} + +AllIn1LightData GetMainLightData(float3 vertexWS, EffectsData effectsData, AllIn1GI gi) +{ + AllIn1LightData lightData; + + #if defined(SUBTRACTIVE_LIGHTING) + lightData.lightColor = 0; + lightData.lightDir = GetMainLightDir(vertexWS); + lightData.realtimeShadow = 1.0; + lightData.distanceAttenuation = 1.0; + lightData.shadowColor = 1.0; + #else + lightData.lightColor = GetMainLightColorRGB(); + lightData.lightDir = GetMainLightDir(vertexWS); + + #if defined(_LIGHTMODEL_NONE) + lightData.realtimeShadow = 1.0; + #else + #ifdef _RECEIVE_SHADOWS_ON + lightData.realtimeShadow = GetShadowAttenuation(effectsData, gi); + #if defined(_RECEIVEDSHADOWSTYPE_STYLIZED) && !defined(FORWARD_ADD_PASS) + lightData.realtimeShadow = AntiAliasing(lightData.realtimeShadow, ACCESS_PROP_FLOAT(_ShadowCutoff)); + #endif + #else + lightData.realtimeShadow = 1.0; + #endif + #endif + + #ifdef _LIGHTMODEL_FASTLIGHTING + lightData.shadowColor = 1.0; + #else + #ifdef FORWARD_ADD_PASS + lightData.shadowColor = lightData.realtimeShadow; + #else + lightData.shadowColor = lerp(SHADOW_COLOR, 1.0, lightData.realtimeShadow); + #endif + #endif + + lightData.distanceAttenuation = 1.0; + #endif + + lightData.layerMask = 1.0; + + return lightData; +} + +float3 GetPointLightPosition(int index) +{ + float3 pointLightPosition = float3(unity_4LightPosX0[index], unity_4LightPosY0[index], unity_4LightPosZ0[index]); + return pointLightPosition; +} + +AllIn1LightData GetPointLightData(int index, float3 vertexWS, float3 normalWS, EffectsData effectsData, AllIn1GI gi) +{ + return GetPointLightData(vertexWS, normalWS, GetPointLightPosition(index), unity_LightColor[index], unity_4LightAtten0[index], effectsData, gi); +} + +FragmentDataShadowCaster GetClipPosShadowCaster( /*VertexData v*/VertexData v, FragmentDataShadowCaster o) +{ + //float4 res = 0; +//#if defined(SHADOWS_CUBE) && !defined(SHADOWS_CUBE_IN_DEPTH_TEX) +// // Rendering into point light (cubemap) shadows +// //#define TRANSFER_SHADOW_CASTER_NOPOS(o,opos) o.vec = mul(unity_ObjectToWorld, v.vertex).xyz - _LightPositionRange.xyz; opos = UnityObjectToClipPos(v.vertex); +// //#define SHADOW_CASTER_FRAGMENT(i) return UnityEncodeCubeShadowDepth ((length(i.vec) + unity_LightShadowBias.x) * _LightPositionRange.w); + +// float3 vec = mul(unity_ObjectToWorld, v.vertex).xyz - _LightPositionRange.xyz; +// res = UnityObjectToClipPos(v.vertex); +//#else +// // Rendering into directional or spot light shadows +// res = UnityClipSpaceShadowCasterPos(v.vertex, v.normal); +// res = UnityApplyLinearShadowBias(res); +// #endif + + //res = UnityClipSpaceShadowCasterPos(v.vertex.xyz, v.normal); + //res = UnityApplyLinearShadowBias(res); + + TRANSFER_SHADOW_CASTER_NORMALOFFSET(o); + return o; + + //return res; +} + +//float GetShadowAttenuation(FragmentData i, float3 vertexWS) +//{ +// //float shadowAttenuation = UNITY_SHADOW_ATTENUATION(i, vertexWS); + +// //float3 lightCoord = mul(unity_WorldToLight, float4(vertexWS, 1)).xyz; +// // fixed shadow = UNITY_SHADOW_ATTENUATION(i, vertexWS); +// // float res = tex2D(_LightTexture0, dot(lightCoord, lightCoord).rr).r * shadow; + +// /*TODO: Fix this*/ +// //shadowAttenuation = 1.0; + +// UNITY_LIGHT_ATTENUATION(attenuation, i, vertexWS); + +// return attenuation; +//} + +ShadowCoordStruct GetShadowCoords(VertexData v, float4 clipPos, float3 vertexWS, float2 uvLightmap) +{ + ShadowCoordStruct res; + + res.pos = clipPos; + res._ShadowCoord = 0; + + UNITY_TRANSFER_SHADOW(res, uvLightmap); + + return res; +} + +float3 GetLightmap(float2 uvLightmap, EffectsData data) +{ + float3 res = 0.0; +#if defined(_AFFECTED_BY_LIGHTMAPS_ON) && defined(LIGHTMAP_ON) + res = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, uvLightmap)); + #ifdef SUBTRACTIVE_LIGHTING + float attenuation = GetShadowAttenuation(data); + float ndotl = saturate(dot(data.normalWS, _WorldSpaceLightPos0.xyz)); + float3 shadowedLightEstimate = + ndotl * (1 - attenuation) * _LightColor0.rgb; + float3 subtractedLight = res - shadowedLightEstimate; + subtractedLight = max(subtractedLight, unity_ShadowColor.rgb); + subtractedLight = lerp(subtractedLight, res, _LightShadowData.x); + + res = subtractedLight; + #endif +#endif + + return res; +} + +float3 GetAmbientColor(EffectsData data) +{ + float3 res = float3(0, 0, 0); + +#ifdef _CUSTOM_AMBIENT_LIGHT_ON + res = ACCESS_PROP_FLOAT4(_CustomAmbientColor).rgb; +#else + res = ShadeSH9(float4(data.normalWS, 1.0)); +#endif + + return res; +} + +AllIn1GI CalculateGI(float2 uvLightmap, EffectsData data) +{ + AllIn1GI res; + INIT_GI(res); + +#if defined(LIGHTMAP_ON) + res.diffuse = GetLightmap(uvLightmap, data); +#else + res.diffuse = GetAmbientColor(data); +#endif + +#if defined(SHADOWS_SHADOWMASK) + res.shadowMask = UnitySampleBakedOcclusion(uvLightmap, data.vertexWS); +#endif + + res.uvLightmap = uvLightmap; + + return res; +} + +//float GetFogFactor(FragmentData fragmentData) +//{ +// float res = 0; + +//#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2) +// UNITY_TRANSFER_FOG(fragmentData, fragmentData.pos); +// res = fragmentData.fogCoord; +//#endif + +// return res; +//} + +float GetFogFactor(float4 clipPos) +{ + float res = 0; +#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2) + FogStruct fogStruct; + UNITY_TRANSFER_FOG(fogStruct, clipPos); + res = fogStruct.fogCoord; +#endif + + return res; +} + + +#if defined(FOG_ENABLED) +float4 CustomMixFog(float fogFactor, float4 col) +{ + float4 res = col; + UNITY_APPLY_FOG(fogFactor, res); + return res; +} +#endif + +#ifdef REFLECTIONS_ON + +float3 BoxProjection ( + float3 direction, float3 position, + float4 cubemapPosition, float3 boxMin, float3 boxMax +) { + #if UNITY_SPECCUBE_BOX_PROJECTION + UNITY_BRANCH + if (cubemapPosition.w > 0) { + float3 factors = + ((direction > 0 ? boxMax : boxMin) - position) / direction; + float scalar = min(min(factors.x, factors.y), factors.z); + direction = direction * scalar + (position - cubemapPosition); + } + #endif + return direction; +} + +float3 GetReflectionsSimple(float3 worldRefl, float cubeLod, float3 positionWS) +{ + float3 reflUV0 = BoxProjection(worldRefl, positionWS, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax); + float4 probe0HDR = UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, reflUV0, cubeLod); + float3 probe0 = DecodeHDR(probe0HDR, unity_SpecCube0_HDR); + + + float3 res = probe0; +#if UNITY_SPECCUBE_BLENDING + float interpolator = unity_SpecCube0_BoxMin.w; + + if(interpolator < 0.99999) + { + float3 reflUV1 = BoxProjection(worldRefl, positionWS, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax); + float4 probe1HDR = UNITY_SAMPLE_TEXCUBE_SAMPLER_LOD(unity_SpecCube1, unity_SpecCube0, reflUV1, cubeLod); + float3 probe1 = DecodeHDR(probe1HDR, unity_SpecCube1_HDR); + + res = lerp(probe1, probe0, interpolator); + } + else + { + res = probe0; + } +#endif + + return res; +} + +float3 GetSkyColor(float3 positionWS, float2 normalizedScreenSpaceUV, + float3 normalWS, float3 viewDirWS, float cubeLod) +{ + float3 worldRefl = normalize(reflect(-viewDirWS, normalWS)); + + float3 res = GetReflectionsSimple(worldRefl, cubeLod, positionWS); + +#ifdef _REFLECTIONS_TOON + float posterizationLevel = lerp(2, 20, ACCESS_PROP_FLOAT(_ToonFactor)); + res = floor(res * posterizationLevel) / posterizationLevel; +#endif + + res *= ACCESS_PROP_FLOAT(_ReflectionsAtten); + + return res; +} +#endif + +float3 ShadeSH(float4 normalWS) +{ + float3 res = ShadeSH9(normalWS); + return res; +} + + +#define NUM_ADDITIONAL_LIGHTS 4; + +#define OBJECT_TO_CLIP_SPACE(v) UnityObjectToClipPos(v.vertex) +#define OBJECT_TO_CLIP_SPACE_FLOAT4(pos) UnityObjectToClipPos(pos) +#define ALLIN1_APPLY_CROSSFADE(input) \ + float2 __vpos = i.projPos.xy / i.projPos.w * _ScreenParams.xy; \ + UNITY_APPLY_DITHER_CROSSFADE(__vpos); + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl.meta new file mode 100644 index 0000000..68ed7f7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 3b763fe4d437215438f3b41484c21752 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_BIRP.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_URP.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_URP.hlsl new file mode 100644 index 0000000..10052dd --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_URP.hlsl @@ -0,0 +1,629 @@ +#ifndef ALLIN13DSHADER_HELPER_URP_INCLUDED +#define ALLIN13DSHADER_HELPER_URP_INCLUDED + +#define NUM_ADDITIONAL_LIGHTS GetNumAdditionalLights(); + +#define OBJECT_TO_WORLD_MATRIX GetObjectToWorldMatrix() + +#if defined(ALLIN1_DECALS_SUPPORT) && defined(_DBUFFER) + #define ALLIN1_DECALS_READY_TO_USE + + #if defined(_DBUFFER_MRT1) || defined(_DBUFFER_MRT2) || defined(_DBUFFER_MRT3) + #define ALLIN1_DECAL_MODE_DBUFFER + #else + #define ALLIN1_DECAL_MODE_SCREEN_SPACE + #endif +#endif + +#ifdef REQUIRE_SCENE_DEPTH + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl" + + float GetRawDepth(float4 projPos) + { + float res = SampleSceneDepth(projPos.xy / projPos.w); + return res; + } + + float GetLinearDepth01(float4 projPos) + { + float rawDepth = GetRawDepth(projPos); + float res = Linear01Depth (rawDepth, _ZBufferParams); + + return res; + } + + float GetSceneDepthDiff(float4 projPos) + { + float rawDepth = GetRawDepth(projPos); + float res = LinearEyeDepth(rawDepth, _ZBufferParams) - projPos.z; + + return res; + } + +#endif + +float3 GetNormalWS(float3 normalOS) +{ + float3 normalWS = TransformObjectToWorldNormal(normalOS); + return normalWS; +} + +float3 GetViewDirWS(float3 vertexWS) +{ + float3 res = GetWorldSpaceViewDir(vertexWS); + return res; +} + +float3 GetPositionVS(float3 positionOS) +{ + float3 res = TransformWorldToView(positionOS); + return res; +} + +float3 GetPositionWS(float4 positionOS) +{ + return TransformObjectToWorld(positionOS.xyz); +} + +float3 GetPositionOS(float4 positionWS) +{ + return TransformWorldToObject(positionWS.xyz); + +} + +float3 GetDirWS(float4 dirOS) +{ + return TransformObjectToWorldDir(dirOS.xyz); +} + +float3 GetDirOSFloat3(float3 dirOS) +{ + return TransformObjectToWorldDir(dirOS.xyz); +} + +float3 GetDirOS(float4 dirOS) +{ + return GetDirOSFloat3(dirOS.xyz); +} + +float3 GetMainLightDir(float3 vertexWS) +{ +#ifdef _LIGHTMODEL_FASTLIGHTING + float3 res = global_lightDirection; +#else + float3 res = GetMainLight().direction; +#endif + + return res; +} + +float3 GetMainLightColorRGB() +{ +#ifdef _LIGHTMODEL_FASTLIGHTING + float3 res = global_lightColor.rgb; +#else + float3 res = GetMainLight().color; +#endif + + return res; +} + +float2 GetSSAO(float2 normalizedScreenSpaceUV, float alpha) +{ + AmbientOcclusionFactor aoFactorURP = GetScreenSpaceAmbientOcclusion(normalizedScreenSpaceUV); + +#if defined(_ALLIN13D_SURFACE_TRANSPARENT) + float2 res = float2(1, 1); +#else + float2 res = float2(aoFactorURP.directAmbientOcclusion, aoFactorURP.indirectAmbientOcclusion); +#endif + + return res; +} + +//normalWS needed for the equivalent method in BIRP +//effectsData needed for the equivalent method in BIRP +AllIn1LightData GetPointLightData(int index, float3 vertexWS, float3 normalWS, EffectsData effectsData, AllIn1GI gi) +{ + AllIn1LightData lightData; + + Light additionalLight = GetAdditionalLight(index, vertexWS, gi.shadowMask); + lightData.lightColor = additionalLight.color; + lightData.lightDir = additionalLight.direction; + +#ifdef _CLUSTER_LIGHT_LOOP + int lightIndex = index; +#else + int lightIndex = GetPerObjectLightIndex(index); +#endif + +#if defined(_LIGHT_COOKIES) + float3 cookieColor = SampleAdditionalLightCookie(lightIndex, effectsData.vertexWS); + lightData.lightColor *= cookieColor; +#endif + +#ifdef _RECEIVE_SHADOWS_ON + lightData.realtimeShadow = additionalLight.shadowAttenuation; +#else + lightData.realtimeShadow = 1.0; +#endif + + lightData.distanceAttenuation = additionalLight.distanceAttenuation; + lightData.shadowColor = lightData.realtimeShadow; + lightData.layerMask = additionalLight.layerMask; + + return lightData; +} + +AllIn1LightData GetMainLightData(float3 vertexWS, EffectsData effectsData, AllIn1GI gi) +{ + AllIn1LightData lightData; + +#if defined(_LIGHTMODEL_NONE) + lightData.lightColor = float3(1.0, 1.0, 1.0); + lightData.lightDir = float3(0.0, 1.0, 0.0); + lightData.distanceAttenuation = 1.0; + lightData.shadowColor = 1.0; + lightData.realtimeShadow = 1.0; + lightData.layerMask = 1; +#elif defined(_LIGHTMODEL_FASTLIGHTING) + lightData.lightColor = global_lightColor; + lightData.lightDir = global_lightDirection; + lightData.distanceAttenuation = 1.0; + lightData.shadowColor = 1.0; + lightData.realtimeShadow = 1.0; + lightData.layerMask = 1; +#else + Light mainLight = GetMainLight(); + lightData.lightColor = mainLight.color; + lightData.lightDir = mainLight.direction; + + lightData.distanceAttenuation = mainLight.distanceAttenuation; + + float4 shadowCoords = TransformWorldToShadowCoord(vertexWS); + #ifdef _RECEIVE_SHADOWS_ON + lightData.realtimeShadow = MainLightRealtimeShadow(shadowCoords); + #if defined(_RECEIVEDSHADOWSTYPE_STYLIZED) + lightData.realtimeShadow = AntiAliasing(lightData.realtimeShadow, ACCESS_PROP_FLOAT(_ShadowCutoff)); + #endif + + float shadowFade = GetMainLightShadowFade(effectsData.vertexWS); + float shadowMask = 1.0; + #if defined(SHADOWS_SHADOWMASK) + shadowMask = gi.shadowMask.r; + #endif + lightData.realtimeShadow = lerp(lightData.realtimeShadow, shadowMask, shadowFade); + #else + lightData.realtimeShadow = 1.0; + #endif + + lightData.shadowColor = lightData.realtimeShadow; + lightData.layerMask = mainLight.layerMask; + + #if defined(_LIGHT_COOKIES) + float3 cookieColor = SampleMainLightCookie(effectsData.vertexWS); + lightData.lightColor *= cookieColor; + #endif +#endif + + return lightData; +} + +int GetNumAdditionalLights() +{ + return GetAdditionalLightsCount(); +} + +/*Needed for URP shadow caster pass*/ +float3 _LightDirection; +float3 _LightPosition; +/************/ +FragmentDataShadowCaster GetClipPosShadowCaster(VertexData v, FragmentDataShadowCaster input) +{ + float3 positionWS = TransformObjectToWorld(v.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(v.normal); + +#if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - positionWS); +#else + float3 lightDirectionWS = _LightDirection; +#endif + + float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS)); + +#if UNITY_REVERSED_Z + positionCS.z = min(positionCS.z, UNITY_NEAR_CLIP_VALUE); +#else + positionCS.z = max(positionCS.z, UNITY_NEAR_CLIP_VALUE); +#endif + + input.pos = positionCS; + return input; +} + +ShadowCoordStruct GetShadowCoords(VertexData v, float4 clipPos, float3 vertexWS, float2 uvLightmap) +{ + ShadowCoordStruct res; + + res._ShadowCoord = 0; + res.pos = clipPos; + + return res; +} + +float GetShadowAttenuation(EffectsData data) +{ + float res = 1.0; + +#if !defined(_LIGHTMODEL_FASTLIGHTING) + + float4 shadowCoords = TransformWorldToShadowCoord(data.vertexWS); + + float mainLightShadow = MainLightRealtimeShadow(shadowCoords); + + //int numAdditionalLights = NUM_ADDITIONAL_LIGHTS; + //float additionalLightsShadows = 1.0; + res = mainLightShadow; + //for(int lightIndex = 0; lightIndex < numAdditionalLights; lightIndex++) + //{ + // Light additionalLight = GetAdditionalLight(lightIndex, vertexWS); + // float additionalLightShadow = AdditionalLightRealtimeShadow(lightIndex, vertexWS/*, additionalLight.direction*/) * additionalLight.distanceAttenuation; + + // res *= additionalLightShadow; + //} +#endif + + return res; +} + +//float GetShadowAttenuation(float3 vertexWS) +//{ +// float4 shadowCoords = TransformWorldToShadowCoord(vertexWS); +// float mainLightShadow = MainLightRealtimeShadow(shadowCoords); + +// float res = mainLightShadow; +// int numAdditionalLights = NUM_ADDITIONAL_LIGHTS; +// for(int lightIndex = 0; lightIndex < numAdditionalLights; lightIndex++) +// { +// Light additionalLight = GetAdditionalLight(lightIndex, vertexWS); +// float additionalLightShadow = AdditionalLightRealtimeShadow(lightIndex, vertexWS) * additionalLight.distanceAttenuation; + +// res += additionalLightShadow; +// } + +// res = 1.0; +// return res; +//} + +float3 GetLightmap(float2 uvLightmap, EffectsData data) +{ + float3 res = 0.0; + +#if defined(_AFFECTED_BY_LIGHTMAPS_ON) && defined(LIGHTMAP_ON) + res = SampleLightmap(uvLightmap, data.normalWS); + #ifdef SUBTRACTIVE_LIGHTING + AllIn1LightData mainLight = GetMainLightData(data.vertexWS, data); + float attenuation = mainLight.realtimeShadow; + float ndotl = saturate(dot(data.normalWS, mainLight.lightDir)); + float3 shadowedLightEstimate = + ndotl * (1 - attenuation) * mainLight.lightColor.rgb; + float3 subtractedLight = res - shadowedLightEstimate; + subtractedLight = max(subtractedLight, _SubtractiveShadowColor.xyz); + subtractedLight = lerp(subtractedLight, res, attenuation); + + res = subtractedLight; + #endif +#endif + + return res; +} + +uint AllIn1GetMeshRenderingLayer() +{ + uint res; + #if UNITY_VERSION >= 202230 + res = GetMeshRenderingLayer(); + #else + res = GetMeshRenderingLightLayer(); + #endif + + return res; +} + +float3 GetAmbientColor(EffectsData data) +{ + float3 res = float3(0, 0, 0); +#if !defined(LIGHTMAP_ON) + #if defined(_CUSTOM_AMBIENT_LIGHT_ON) + res = ACCESS_PROP_FLOAT4(_CustomAmbientColor).rgb; + #else + #if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2) + half3 bakedGI; + float4 probeOcclusion; + EvaluateAdaptiveProbeVolume(data.vertexWS.xyz, data.normalWS.xyz, data.viewDirWS.xyz, + data.projPos.xy, AllIn1GetMeshRenderingLayer(), + bakedGI, probeOcclusion); + res = bakedGI; + #else + res = SampleSH(data.normalWS); + #endif + #endif + +#endif + + return res; +} + +AllIn1GI CalculateGI(float2 uvLightmap, EffectsData data) +{ + AllIn1GI res; + INIT_GI(res); + +#if defined(LIGHTMAP_ON) + res.diffuse = GetLightmap(uvLightmap, data); +#else + res.diffuse = GetAmbientColor(data); +#endif + +#if defined(SHADOWS_SHADOWMASK) + res.shadowMask = SAMPLE_TEXTURE2D(unity_ShadowMask, samplerunity_ShadowMask, uvLightmap); +#endif + + return res; +} + +float GetFogFactor(float4 clipPos) +{ + float res = 0; + +#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2) + res = ComputeFogFactor(clipPos.z); +#endif + + return res; +} + +#if defined(FOG_ENABLED) +float4 CustomMixFog(float fogFactor, float4 col) +{ + float4 res = col; + res.rgb = MixFog(res.rgb, fogFactor); + return res; +} +#endif + +void ConfigureDecalData(inout AllIn1DecalData allIn1Decal, float4 positionCS) +{ +#if defined(_DBUFFER) + FETCH_DBUFFER(DBuffer, _DBufferTexture, int2(positionCS.xy)); + + DecalSurfaceData decalSurfaceData; + DECODE_FROM_DBUFFER(DBuffer, decalSurfaceData); + + allIn1Decal.baseColor = decalSurfaceData.baseColor; + allIn1Decal.emissive = decalSurfaceData.emissive; + allIn1Decal.mask = step(0.1, allIn1Decal.baseColor.a); + allIn1Decal.mask = saturate(allIn1Decal.mask + decalSurfaceData.normalWS.w); + allIn1Decal.MAOSAlpha = decalSurfaceData.MAOSAlpha; + allIn1Decal.smoothness = decalSurfaceData.smoothness; + allIn1Decal.metallic = decalSurfaceData.metallic; + + float4 normalTS = decalSurfaceData.normalWS; //Even if it's called normalWS, the content is a sampled normal map in tangent space + + allIn1Decal.normalTS = lerp(normalTS, DEFAULT_NORMAL_MAP_VALUE, allIn1Decal.mask); + allIn1Decal.unpackedNormal = UnpackNormal(allIn1Decal.normalTS); +#endif +} + +#ifdef REFLECTIONS_ON + +float3 BoxProjection ( + float3 direction, float3 position, + float4 cubemapPosition, float3 boxMin, float3 boxMax +) { + #if UNITY_SPECCUBE_BOX_PROJECTION + UNITY_BRANCH + if (cubemapPosition.w > 0) { + float3 factors = + ((direction > 0 ? boxMax : boxMin) - position) / direction; + float scalar = min(min(factors.x, factors.y), factors.z); + direction = direction * scalar + (position - cubemapPosition.xyz); + } + #endif + return direction; +} + +float3 GetReflectionsSimple(float3 worldRefl, float cubeLod, float3 positionWS) +{ + half probe0Volume = CalculateProbeVolumeSqrMagnitude(unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax); + half probe1Volume = CalculateProbeVolumeSqrMagnitude(unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax); + + half volumeDiff = probe0Volume - probe1Volume; + float importanceSign = unity_SpecCube1_BoxMin.w; + + float desiredWeightProbe0 = CalculateProbeWeight(positionWS, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax); + float desiredWeightProbe1 = CalculateProbeWeight(positionWS, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax); + + // A probe is dominant if its importance is higher + // Or have equal importance but smaller volume + bool probe0Dominant = importanceSign > 0.0f || (importanceSign == 0.0f && volumeDiff < -0.0001h); + bool probe1Dominant = importanceSign < 0.0f || (importanceSign == 0.0f && volumeDiff > 0.0001h); + + float weightProbe0 = probe1Dominant ? min(desiredWeightProbe0, 1.0f - desiredWeightProbe1) : desiredWeightProbe0; + float weightProbe1 = probe0Dominant ? min(desiredWeightProbe1, 1.0f - desiredWeightProbe0) : desiredWeightProbe1; + + float totalWeight = weightProbe0 + weightProbe1; + + // If either probe 0 or probe 1 is dominant the sum of weights is guaranteed to be 1. + // If neither is dominant this is not guaranteed - only normalize weights if totalweight exceeds 1. + weightProbe0 /= max(totalWeight, 1.0f); + weightProbe1 /= max(totalWeight, 1.0f); + + float3 res = 0; + if(weightProbe0 > 0.01) + { + float3 reflUV0 = BoxProjection(worldRefl, positionWS, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin.xyz, unity_SpecCube0_BoxMax.xyz); + float4 probe0HDR = SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflUV0, cubeLod); + float3 probe0 = DecodeHDREnvironment(probe0HDR, unity_SpecCube0_HDR); + + res += weightProbe0 * probe0; + } + if(weightProbe1 > 0.01f) + { + float3 reflUV1 = BoxProjection(worldRefl, positionWS, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin.xyz, unity_SpecCube1_BoxMax.xyz); + float4 probe1HDR = SAMPLE_TEXTURECUBE_LOD(unity_SpecCube1, samplerunity_SpecCube0, reflUV1, cubeLod); + float3 probe1 = DecodeHDREnvironment(probe1HDR, unity_SpecCube1_HDR); + + res += weightProbe1 * probe1; + } + if(totalWeight < 0.99) + { + float4 glossyEnvironmentHDR = SAMPLE_TEXTURECUBE_LOD(_GlossyEnvironmentCubeMap, sampler_GlossyEnvironmentCubeMap, worldRefl, cubeLod); + float3 glossyEnvironment = DecodeHDREnvironment(glossyEnvironmentHDR, _GlossyEnvironmentCubeMap_HDR); + + res += (1.0f - totalWeight) * glossyEnvironment; + } + + return res; +} + +float3 GetReflectionsCluster(float3 positionWS, float2 normalizedScreenSpaceUV, float3 worldRefl, float cubeLod) +{ + float3 res = 0; + float3 irradiance = float3(0, 0, 0); + float mip = cubeLod; +#if USE_CLUSTER_LIGHT_LOOP && CLUSTER_HAS_REFLECTION_PROBES + float totalWeight = 0.0f; + uint probeIndex; + ClusterIterator it = ClusterInit(normalizedScreenSpaceUV, positionWS, 1); + [loop] while (ClusterNext(it, probeIndex) && totalWeight < 0.99f) + { + probeIndex -= URP_FP_PROBES_BEGIN; + + float weight = CalculateProbeWeight(positionWS, urp_ReflProbes_BoxMin[probeIndex], urp_ReflProbes_BoxMax[probeIndex]); + weight = min(weight, 1.0f - totalWeight); + + half3 sampleVector = worldRefl; + #ifdef _REFLECTION_PROBE_BOX_PROJECTION + sampleVector = BoxProjectedCubemapDirection(worldRefl, positionWS, urp_ReflProbes_ProbePosition[probeIndex], urp_ReflProbes_BoxMin[probeIndex], urp_ReflProbes_BoxMax[probeIndex]); + #endif // _REFLECTION_PROBE_BOX_PROJECTION + + uint maxMip = (uint)abs(urp_ReflProbes_ProbePosition[probeIndex].w) - 1; + half probeMip = min(mip, maxMip); + float2 uv = saturate(PackNormalOctQuadEncode(sampleVector) * 0.5 + 0.5); + + float mip0 = floor(probeMip); + float mip1 = mip0 + 1; + float mipBlend = probeMip - mip0; + float4 scaleOffset0 = urp_ReflProbes_MipScaleOffset[probeIndex * 7 + (uint)mip0]; + float4 scaleOffset1 = urp_ReflProbes_MipScaleOffset[probeIndex * 7 + (uint)mip1]; + + half3 irradiance0 = half4(SAMPLE_TEXTURE2D_LOD(urp_ReflProbes_Atlas, sampler_LinearClamp, uv * scaleOffset0.xy + scaleOffset0.zw, 0.0)).rgb; + half3 irradiance1 = half4(SAMPLE_TEXTURE2D_LOD(urp_ReflProbes_Atlas, sampler_LinearClamp, uv * scaleOffset1.xy + scaleOffset1.zw, 0.0)).rgb; + res += weight * lerp(irradiance0, irradiance1, mipBlend); + totalWeight += weight; + } +#else + half probe0Volume = CalculateProbeVolumeSqrMagnitude(unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax); + half probe1Volume = CalculateProbeVolumeSqrMagnitude(unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax); + + half volumeDiff = probe0Volume - probe1Volume; + float importanceSign = unity_SpecCube1_BoxMin.w; + + // A probe is dominant if its importance is higher + // Or have equal importance but smaller volume + bool probe0Dominant = importanceSign > 0.0f || (importanceSign == 0.0f && volumeDiff < -0.0001h); + bool probe1Dominant = importanceSign < 0.0f || (importanceSign == 0.0f && volumeDiff > 0.0001h); + + float desiredWeightProbe0 = CalculateProbeWeight(positionWS, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax); + float desiredWeightProbe1 = CalculateProbeWeight(positionWS, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax); + + // Subject the probes weight if the other probe is dominant + float weightProbe0 = probe1Dominant ? min(desiredWeightProbe0, 1.0f - desiredWeightProbe1) : desiredWeightProbe0; + float weightProbe1 = probe0Dominant ? min(desiredWeightProbe1, 1.0f - desiredWeightProbe0) : desiredWeightProbe1; + + float totalWeight = weightProbe0 + weightProbe1; + + // If either probe 0 or probe 1 is dominant the sum of weights is guaranteed to be 1. + // If neither is dominant this is not guaranteed - only normalize weights if totalweight exceeds 1. + weightProbe0 /= max(totalWeight, 1.0f); + weightProbe1 /= max(totalWeight, 1.0f); + + // Sample the first reflection probe + if (weightProbe0 > 0.01f) + { + half3 reflectVector0 = worldRefl; +#ifdef _REFLECTION_PROBE_BOX_PROJECTION + reflectVector0 = BoxProjectedCubemapDirection(worldRefl, positionWS, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax); +#endif // _REFLECTION_PROBE_BOX_PROJECTION + + half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectVector0, mip)); + + irradiance += weightProbe0 * DecodeHDREnvironment(encodedIrradiance, unity_SpecCube0_HDR); + } + + // Sample the second reflection probe + if (weightProbe1 > 0.01f) + { + half3 reflectVector1 = worldRefl; +#ifdef _REFLECTION_PROBE_BOX_PROJECTION + worldRefl = BoxProjectedCubemapDirection(worldRefl, positionWS, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax); +#endif // _REFLECTION_PROBE_BOX_PROJECTION + half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(unity_SpecCube1, samplerunity_SpecCube1, worldRefl, mip)); + + irradiance += weightProbe1 * DecodeHDREnvironment(encodedIrradiance, unity_SpecCube1_HDR); + } + + res = irradiance; +#endif + + // Use any remaining weight to blend to environment reflection cube map + if (totalWeight < 0.99f) + { + half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(_GlossyEnvironmentCubeMap, sampler_GlossyEnvironmentCubeMap, worldRefl, mip)); + + res += (1.0f - totalWeight) * DecodeHDREnvironment(encodedIrradiance, _GlossyEnvironmentCubeMap_HDR); + } + + return res; +} + +float3 GetSkyColor(float3 positionWS, float2 normalizedScreenSpaceUV, float3 normalWS, float3 viewDirWS, float cubeLod) +{ + float3 worldRefl = normalize(reflect(-viewDirWS, normalWS)); + float4 skyData = 0; + float3 res = 0; + +#ifdef _REFLECTION_PROBE_BLENDING + #if USE_CLUSTER_LIGHT_LOOP && CLUSTER_HAS_REFLECTION_PROBES + res = GetReflectionsCluster(positionWS, normalizedScreenSpaceUV, worldRefl, cubeLod); + #else + res = GetReflectionsSimple(worldRefl, cubeLod, positionWS); + #endif +#else + res = GetReflectionsSimple(worldRefl, cubeLod, positionWS); +#endif + +#ifdef _REFLECTIONS_TOON + float posterizationLevel = lerp(2, 20, ACCESS_PROP_FLOAT(_ToonFactor)); + res = floor(res * posterizationLevel) / posterizationLevel; +#endif + + res *= ACCESS_PROP_FLOAT(_ReflectionsAtten); + + return res; +} +#endif + +float3 ShadeSH(float4 normalWS) +{ + float3 res = SampleSH(normalWS.xyz); + return res; +} + +#define OBJECT_TO_CLIP_SPACE(v) TransformObjectToHClip(v.vertex.xyz) +#define OBJECT_TO_CLIP_SPACE_FLOAT4(pos) TransformObjectToHClip(pos.xyz) +#define ALLIN1_APPLY_CROSSFADE(input) LODFadeCrossFade(input.pos); + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_URP.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_URP.hlsl.meta new file mode 100644 index 0000000..5c9b4ba --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_URP.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 29e55f1233e1c0c4c8080ca68ec48682 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderHelper_URP.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLight.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLight.hlsl new file mode 100644 index 0000000..4622f98 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLight.hlsl @@ -0,0 +1,347 @@ +#ifndef ALLIN13DSHADER_LIGHT_INCLUDED +#define ALLIN13DSHADER_LIGHT_INCLUDED + + +#if ALLIN1_USE_FORWARD_PLUS + #define LIGHT_LOOP_BEGIN_ALLIN13D(lightCount, data) { \ + uint lightIndex; \ + ClusterIterator _urp_internal_clusterIterator = ClusterInit(data.normalizedScreenSpaceUV, data.vertexWS, 0); \ + [loop] while (ClusterNext(_urp_internal_clusterIterator, lightIndex)) { \ + lightIndex += URP_FP_DIRECTIONAL_LIGHTS_COUNT; \ + ALLIN1_FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK + #define LIGHT_LOOP_END_ALLIN13D } } +#else + #define LIGHT_LOOP_BEGIN_ALLIN13D(lightCount, data) \ + if(lightCount > 0) { \ + for (uint lightIndex = 0u; lightIndex < lightCount; ++lightIndex) { + #define LIGHT_LOOP_END_ALLIN13D } } +#endif + +float GetMainLightIntensity() +{ + return length(GetMainLightColorRGB()); +} + +#if defined(_SHADINGMODEL_PBR) || defined(_SPECULARMODEL_ANISOTROPIC) || defined(_SPECULARMODEL_ANISOTROPICTOON) + #include "../ShaderLibrary/AllIn13DShader_BRDF.hlsl" +#endif + +float3 GetBitangentWS(float4 tangentOS, float3 tangentWS, float3 normalWS) +{ + float tangentSign = tangentOS.w * unity_WorldTransformParams.w; + float3 res = cross(normalWS, tangentWS) * tangentSign; + return res; +} + +float3 DiffuseTerm(AllIn1LightData lightData, float3 normal, float isAdditionalLight) +{ + float rawNdotL = dot(normal, lightData.lightDir); + float3 lightModel = 0; + float3 lightColor = lightData.lightColor.rgb * lightData.distanceAttenuation * lightData.shadowColor.rgb; + +#if !defined(FORWARD_ADD_PASS) + #if defined(_LIGHTMODEL_HALFLAMBERT) || defined(_LIGHTMODEL_FAKEGI) || defined(_LIGHTMODEL_TOONRAMP) + lightColor = isAdditionalLight > 0 ? lightColor : lightData.lightColor.rgb; + rawNdotL = isAdditionalLight > 0 ? rawNdotL : rawNdotL * GetLuminance(lightData.shadowColor.rgb); + #endif +#endif + +#if defined(_LIGHTMODEL_CLASSIC) + float NdotL = saturate(rawNdotL); + lightModel = NdotL; + +#elif defined(_LIGHTMODEL_TOON) + float NdotL = saturate(rawNdotL); + lightModel = smoothstep(ACCESS_PROP_FLOAT(_ToonCutoff), ACCESS_PROP_FLOAT(_ToonCutoff) + ACCESS_PROP_FLOAT(_ToonSmoothness), NdotL); + +#elif defined(_LIGHTMODEL_TOONRAMP) + float NdotL = (rawNdotL * 0.5) + 0.5; + lightModel = SAMPLE_TEX2D_LOD(_ToonRamp, float4(NdotL, 0, 0, 0)).rgb; + +#elif defined(_LIGHTMODEL_HALFLAMBERT) + float NdotL = saturate(rawNdotL); + float halfLambertTerm = (NdotL * ACCESS_PROP_FLOAT(_HalfLambertWrap)) + (1 - ACCESS_PROP_FLOAT(_HalfLambertWrap)); + lightModel = halfLambertTerm * halfLambertTerm; + +#elif defined(_LIGHTMODEL_FAKEGI) + float NdotL = saturate(rawNdotL); + lightModel = (NdotL * ACCESS_PROP_FLOAT(_HardnessFakeGI)) + 1.0 - ACCESS_PROP_FLOAT(_HardnessFakeGI); + +#elif defined(_LIGHTMODEL_FASTLIGHTING) + lightModel = saturate(rawNdotL); + +#endif + + float3 res = lightModel * lightColor; + + return res; +} + +#ifdef SPECULAR_ON + +float3 SpecularTerm(float3 objectColor, AllIn1LightData lightData, + float3 normalWS, float3 tangentWS, float3 bitangentWS, + float3 viewDirWS, float glossiness, float2 mainUV, float4 specularTex) +{ + float3 lightColor = lightData.lightColor.rgb * lightData.distanceAttenuation * lightData.shadowColor.rgb; + float3 reflectionDir = reflect(-lightData.lightDir, normalWS); + float rawVdotL = dot(viewDirWS, reflectionDir); + + float3 specularModel = 0; + + +#if defined(_SPECULARMODEL_CLASSIC) || defined(_SPECULARMODEL_TOON) + float3 halfVector = normalize(viewDirWS + lightData.lightDir); + float NdotH = saturate(dot(normalWS, halfVector)); + float specularIntensity = pow(NdotH, glossiness); + +#elif defined(_SPECULARMODEL_ANISOTROPIC) || defined(_SPECULARMODEL_ANISOTROPICTOON) + float3 H = normalize(viewDirWS + lightData.lightDir); + + float TdotH = saturate(dot(tangentWS, H)); + float BdotH = saturate(dot(bitangentWS, H)); + + float TdotV = saturate(dot(tangentWS, viewDirWS)); + float BdotV = saturate(dot(bitangentWS, viewDirWS)); + + float TdotL = saturate(dot(tangentWS, lightData.lightDir)); + float BdotL = saturate(dot(bitangentWS, lightData.lightDir)); + + float NdotH = saturate(dot(normalWS, H)); + float NdotL = saturate(dot(normalWS, lightData.lightDir)); + float NdotV = saturate(dot(normalWS, viewDirWS)); + + float VdotH = saturate(dot(viewDirWS, H)); + + float anisotropy = ACCESS_PROP_FLOAT(_Anisotropy); + float anisoShininess = ACCESS_PROP_FLOAT(_AnisoShininess); + float at = max((1 - anisoShininess) * (1.0 + anisotropy), 0.001); + float ab = max((1 - anisoShininess) * (1.0 - anisotropy), 0.001); + + float3 specularIntensity = SpecularAnisoTerm( + at, ab, + float3(1.0, 1.0, 1.0), + NdotH, NdotV, NdotL, + TdotV, BdotV, + TdotL, BdotL, + TdotH, BdotH, + H, tangentWS.xyz, bitangentWS.xyz) * NdotL; + + specularIntensity = saturate(specularIntensity); +#endif + +#if defined(_SPECULARMODEL_ANISOTROPICTOON) || defined(_SPECULARMODEL_TOON) + float specularSmoothness = max(ACCESS_PROP_FLOAT(_SpecularToonSmoothness), 0.001); + specularIntensity = smoothstep(ACCESS_PROP_FLOAT(_SpecularToonCutoff), ACCESS_PROP_FLOAT(_SpecularToonCutoff) + specularSmoothness, specularIntensity); +#endif + + specularModel = specularIntensity * lightColor; + float3 res = specularModel * ACCESS_PROP_FLOAT(_SpecularAtten) * specularTex.r; + + return res; +} + +float3 SpecularTerm_Basic(float3 objectColor, AllIn1LightData lightData, + float3 normalWS, float3 tangentWS, float3 bitangentWS, float3 viewDirWS, float2 mainUV, float4 specularTex) +{ + float3 res = SpecularTerm(objectColor, lightData, + normalWS, tangentWS, bitangentWS, + viewDirWS, ACCESS_PROP_FLOAT(_Shininess) * ACCESS_PROP_FLOAT(_Shininess), mainUV, specularTex); + return res; +} + +#endif + +float3 RimTermOperation(float3 normalWS, float3 viewDirWS, float minRim, float maxRim, float rimAttenuation, float3 rimColor) +{ + float NdotV = saturate(dot(normalWS, viewDirWS)); + float rimIntensity = (1 - NdotV); + rimIntensity = smoothstep(minRim, maxRim, rimIntensity) * rimAttenuation; + + float3 res = rimIntensity * rimColor; + return res; +} + +float3 DirectLighting(float3 objectColor, EffectsData effectsData, AllIn1LightData lightData, float4 specularTex, float isAdditionalLight) +{ + float3 res = 0; + + float3 diffuseTerm = DiffuseTerm(lightData, effectsData.normalWS, isAdditionalLight) * objectColor; + +#if defined(_CUSTOM_SHADOW_COLOR_ON) && !defined(FORWARD_ADD_PASS) + float shadowT = saturate(lightData.realtimeShadow + 1.0 - global_shadowColor.a); + diffuseTerm = lerp(global_shadowColor, diffuseTerm, shadowT); +#endif + + float3 specularTerm = 0; +#ifdef SPECULAR_ON + + float NdotL = saturate(dot(effectsData.normalWS, lightData.lightDir)); + + specularTerm = SpecularTerm_Basic(objectColor, lightData, + effectsData.normalWS, effectsData.tangentWS, effectsData.bitangentWS, + effectsData.viewDirWS, effectsData.mainUV, specularTex) * NdotL; +#endif + + res = diffuseTerm + specularTerm; + + return res; +} + +float3 DirectLighting(float3 objectColor, float2 ssaoFactor, EffectsData effectsData, AllIn1GI gi) +{ + AllIn1LightData mainLightData = GetMainLightData(effectsData.vertexWS, effectsData, gi); + + + float3 res = objectColor; + float4 specularTex = float4(1, 1, 1, 1); + +#ifdef ALLIN1_USE_LIGHT_LAYERS + uint meshRenderingLayers = AllIn1GetMeshRenderingLayer(); + res = 0; + if (IsMatchingLightLayer(mainLightData.layerMask, meshRenderingLayers)) + { + res = objectColor; +#endif + +#ifdef SPECULAR_ON + specularTex = SAMPLE_TEX2D(_SpecularMap, effectsData.mainUV); +#endif + + res = DirectLighting(objectColor, effectsData, mainLightData, specularTex, 0); + +#ifdef ALLIN1_USE_LIGHT_LAYERS + } +#endif + + + +#if defined(ADDITIONAL_LIGHT_LOOP) && !defined(_LIGHTMODEL_FASTLIGHTING) + // Additional light loop for non-main directional lights. This block is specific to Forward+. + #if USE_CLUSTER_LIGHT_LOOP + UNITY_LOOP for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++) + { + AllIn1LightData additionalLightData = GetPointLightData(lightIndex, effectsData.vertexWS, effectsData.normalWS, effectsData, gi); + #ifdef ALLIN1_USE_LIGHT_LAYERS + if (IsMatchingLightLayer(additionalLightData.layerMask, meshRenderingLayers)) + { + #endif + res += DirectLighting(objectColor, effectsData, additionalLightData, specularTex, 1); + #ifdef ALLIN1_USE_LIGHT_LAYERS + } + #endif + } + #endif + + uint numAdditionalLights = NUM_ADDITIONAL_LIGHTS; + LIGHT_LOOP_BEGIN_ALLIN13D(numAdditionalLights, effectsData) + AllIn1LightData additionalLightData = GetPointLightData(lightIndex, effectsData.vertexWS, effectsData.normalWS, effectsData, gi); + #ifdef ALLIN1_USE_LIGHT_LAYERS + if (IsMatchingLightLayer(additionalLightData.layerMask, meshRenderingLayers)) + { + #endif + res += DirectLighting(objectColor, effectsData, additionalLightData, specularTex, 1); + #ifdef ALLIN1_USE_LIGHT_LAYERS + } + #endif + + LIGHT_LOOP_END_ALLIN13D +#endif + + res *= ssaoFactor.x; + + return res; +} + +float3 IndirectLighting_Basic(float3 objectColor, float2 ssaoFactor, EffectsData effectsData, AllIn1GI gi) +{ + //float3 ambientColor = GetAmbientColor(effectsData); + + float3 ao = 1.0; + + float3 reflections = 0; +#ifdef REFLECTIONS_ON + reflections = GetSkyColor(effectsData.vertexWS, effectsData.normalizedScreenSpaceUV, effectsData.normalWS, effectsData.viewDirWS, 1.0); +#endif + + float3 indirectLighting = /*(ambientColor + lightmap)*/gi.diffuse * objectColor; + indirectLighting += reflections; + + indirectLighting *= ssaoFactor.y; + + return indirectLighting; +} + +float3 CalculateLighting_Basic(float3 objectColor, float alpha, EffectsData effectsData, AllIn1GI gi) +{ + float2 ssaoFactor = GetSSAO(effectsData.normalizedScreenSpaceUV.xy, alpha); + + float3 directLighting = DirectLighting(objectColor, ssaoFactor, effectsData, gi); + + + float3 indirectLighting = 0; + //We add IndirectLighting only once +#ifndef FORWARD_ADD_PASS + indirectLighting = IndirectLighting_Basic(objectColor, ssaoFactor, effectsData, gi); + + #ifdef _AOMAP_ON + float3 aoMapValue = GetAOMapTerm(effectsData.mainUV); + indirectLighting *= aoMapValue; + #endif +#endif + + float3 res = directLighting + indirectLighting; + + return res; +} + +#ifdef _SHADINGMODEL_PBR +float3 CalculateLighting_MetallicWorkflow( + float3 vertexWS, + float3 normalWS, float3 tangentWS, float3 bitangentWS, + float3 objectColor, float alpha, + float3 shadows, float3 ambientCol, float3 viewDirWS, + float2 mainUV, FragmentData fragmentData, EffectsData effectsData, AllIn1GI gi) +{ + float3 res = CalculateLighting_PBR(objectColor, alpha, effectsData, gi); + + return res; +} + +#endif + +float3 CalculateLighting(float3 vertexWS, + float3 normalWS, float3 tangentWS, float3 bitangentWS, + float3 objectColor, float alpha, + float shadows, float3 ambientCol, float3 viewDirWS, + float2 mainUV, + float3 lightColor, float3 lightDir, + FragmentData fragmentData, float lightAtten, EffectsData effectsData, + AllIn1GI gi) +{ +#ifdef _CUSTOM_SHADOW_COLOR_ON + float3 shadowColor = lerp(1.0, global_shadowColor, 1 - shadows); +#else + float3 shadowColor = shadows; +#endif + + float3 res = 0; +#ifdef _LIGHTMODEL_FASTLIGHTING + res = CalculateLighting_Basic(objectColor, alpha, effectsData, gi); +#else + #ifdef _SHADINGMODEL_PBR + res = CalculateLighting_MetallicWorkflow( + vertexWS, + normalWS, tangentWS, bitangentWS, + objectColor, alpha, + shadowColor, ambientCol, viewDirWS, + mainUV, fragmentData, effectsData, gi); + #else + res = CalculateLighting_Basic(objectColor, alpha, effectsData, gi); + #endif +#endif + + return res; +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLight.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLight.hlsl.meta new file mode 100644 index 0000000..70b460f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLight.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: a8bd53a2a522aa9488877a9bb281ec11 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLight.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLightAddPass.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLightAddPass.hlsl new file mode 100644 index 0000000..98e0bcf --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLightAddPass.hlsl @@ -0,0 +1,122 @@ +#ifndef ALLIN13DSHADER_LIGHT_ADD_PASS_INCLUDED +#define ALLIN13DSHADER_LIGHT_ADD_PASS_INCLUDED + +#include "../ShaderLibrary/AllIn13DShader_BasePass.hlsl" + +float4 CalculateLightingAdd(float3 vertexWS, float3 normalWS, float3 viewDirWS, + float4 objectColor, float shadows, + float2 mainUV, + FragmentData fragmentData, EffectsData effectsData, + AllIn1GI gi) +{ + float4 col = float4(0, 0, 0, objectColor.a); + col.rgb = CalculateLighting(vertexWS, + normalWS, 0, 0, + objectColor.rgb, objectColor.a, + 0, 0, viewDirWS, + mainUV, + 0, 1.0, fragmentData, 1.0, effectsData, + gi); + + return col; +} + +FragmentData BasicVertexAdd(VertexData v) +{ + FragmentData o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + v.vertex = ApplyVertexEffects(v.vertex, v.normal, 0); + + + POSITION_WS(o) = GetPositionWS(v.vertex); + + o.normalWS = GetNormalWS(v.normal); + + VIEWDIR_WS(o) = GetViewDirWS(POSITION_WS(o)); + + SCALED_MAIN_UV(o) = SIMPLE_CUSTOM_TRANSFORM_TEX(v.uv, _MainTex); + RAW_MAIN_UV(o) = v.uv; + + o.pos = OBJECT_TO_CLIP_SPACE(v); + + ShadowCoordStruct shadowCoordStruct = GetShadowCoords(v, o.pos, POSITION_WS(o), v.uvLightmap); + o._ShadowCoord = shadowCoordStruct._ShadowCoord; + + FOGCOORD(o) = GetFogFactor(o.pos); + +#if defined(LIGHTMAP_ON) || defined(SHADOWS_SHADOWMASK) + UV_LIGHTMAP(o) = v.uvLightmap * unity_LightmapST.xy + unity_LightmapST.zw; +#else + UV_LIGHTMAP(o) = v.uvLightmap; +#endif + +#ifdef REQUIRE_TANGENT_WS + float3 tangentWS = GetDirWS(float4(v.tangent.xyz, 0)); + float3 bitangentWS = GetBitangentWS(v.tangent, tangentWS, o.normalWS); + INIT_T_SPACE(o.normalWS) +#endif + + return o; +} + +float4 BasicFragmentAdd(FragmentData i) : SV_Target +{ + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + +#ifdef _LIGHTMODEL_FASTLIGHTING + float4 additiveRes = 0; +#else + + AllIn1DecalData decalData; + INIT_DECAL_DATA(decalData) + +#ifdef ALLIN1_DECALS_READY_TO_USE + ConfigureDecalData(decalData, i.pos); +#endif + + EffectsData data = CalculateEffectsData(i, decalData); + + data = ApplyUVEffects_FragmentStage(data); + data.normalWS = GetNormalWS(data, i, decalData); + + float4 objectColor = GetBaseColor(data); + + float3 normalOS = data.normalOS; + float3 normalWS = data.normalWS; + float3 viewDirWS = data.viewDirWS; + + objectColor *= ACCESS_PROP_FLOAT4(_Color); + objectColor = ApplyColorEffectsBeforeLighting(objectColor, data); + + float4 col = objectColor; + + AllIn1GI gi = CalculateGI(UV_LIGHTMAP(i), data); + col = CalculateLightingAdd(POSITION_WS(i), normalWS, VIEWDIR_WS(i), objectColor, 1.0, i.mainUV, i, data, gi); + + col = ApplyAlphaEffects(col, + i.mainUV, UV_LIGHTMAP(i), data.vertexWS, + 0, data.camDistance, data.projPos); + +#ifdef _ALPHA_CUTOFF_ON + clip((col.a - ACCESS_PROP_FLOAT(_AlphaCutoffValue)) - 0.001); +#endif + + col = ApplyColorEffectsAfterLighting(col, data); + col.a *= ACCESS_PROP_FLOAT(_GeneralAlpha); + +#if defined(FOG_ENABLED) + col = CustomMixFog(FOGCOORD(i), col); +#endif + + float4 additiveRes = col * col.a; +#endif + + return additiveRes; +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLightAddPass.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLightAddPass.hlsl.meta new file mode 100644 index 0000000..e799b26 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLightAddPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: db308fac201edba41b72ab235b924391 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShaderLightAddPass.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl new file mode 100644 index 0000000..5df5dc1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl @@ -0,0 +1,73 @@ +#ifndef ALLIN13DSHADER_ALPHA_EFFECTS +#define ALLIN13DSHADER_ALPHA_EFFECTS + +#ifdef _FADE_ON +// +// +float4 Fade(float4 inputColor, float2 uv) +{ + float4 res = inputColor; + + float2 fadeUV = SIMPLE_CUSTOM_TRANSFORM_TEX(uv, _FadeTex); + float fadeSample = SAMPLE_TEX2D(_FadeTex, fadeUV).r; + + fadeSample = pow(saturate(fadeSample), ACCESS_PROP_FLOAT(_FadePower)); + +#ifdef _FADE_BURN_ON + float fadeAmount = lerp(ACCESS_PROP_FLOAT(_FadeAmount) - ACCESS_PROP_FLOAT(_FadeTransition) - ACCESS_PROP_FLOAT(_FadeBurnWidth), 1.0, ACCESS_PROP_FLOAT(_FadeAmount)); + float fade = smoothstep(fadeAmount, fadeAmount + ACCESS_PROP_FLOAT(_FadeTransition), fadeSample); + + float fadePlusBurn = smoothstep(fadeAmount + ACCESS_PROP_FLOAT(_FadeBurnWidth), fadeAmount + ACCESS_PROP_FLOAT(_FadeBurnWidth) + ACCESS_PROP_FLOAT(_FadeTransition), fadeSample); + + float diff = saturate(fade - fadePlusBurn); + + float3 burnColor = diff * ACCESS_PROP_FLOAT4(_FadeBurnColor).rgb; + + res.rgb += burnColor; +#else + float fadeAmount = lerp(ACCESS_PROP_FLOAT(_FadeAmount) - ACCESS_PROP_FLOAT(_FadeTransition), 1.0, ACCESS_PROP_FLOAT(_FadeAmount)); + float fade = smoothstep(fadeAmount, fadeAmount + ACCESS_PROP_FLOAT(_FadeTransition), fadeSample); +#endif + + res.a *= fade; + + return res; +} +// +#endif + +#ifdef _INTERSECTION_FADE_ON +float4 IntersectionFade(float4 inputColor, float sceneDepthDiff) +{ + float4 res = inputColor; + + res.a *= saturate(ACCESS_PROP_FLOAT(_IntersectionFadeFactor) * sceneDepthDiff); + + return res; +} +#endif + +#ifdef _FADE_BY_CAM_DISTANCE_ON +// +float4 FadeByCamDistance(float4 inputColor, float camDistance, out float camFadeDistanceNormalized) +{ + float4 res = inputColor; + + float t = 0; +#ifdef _FADE_BY_CAM_DISTANCE_NEAR_FADE + t = 1 - smoothstep(ACCESS_PROP_FLOAT(_MinDistanceToFade), ACCESS_PROP_FLOAT(_MaxDistanceToFade), camDistance); +#else + t = smoothstep(ACCESS_PROP_FLOAT(_MinDistanceToFade), ACCESS_PROP_FLOAT(_MaxDistanceToFade), camDistance); +#endif + + + res.a = lerp(res.a, 0, t); + + camFadeDistanceNormalized = t; + + return res; +} +// +#endif + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl.meta new file mode 100644 index 0000000..53a87c2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 2c256809ff632974b99ea50fa0ab61a3 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_AlphaEffects.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BRDF.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BRDF.hlsl new file mode 100644 index 0000000..abd2004 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BRDF.hlsl @@ -0,0 +1,518 @@ +#ifndef ALLIN13DSHADER_BRDF +#define ALLIN13DSHADER_BRDF + +/************/ +#define MEDIUMP_FLT_MAX 65504.0 +#define saturateMediump(x) min(x, MEDIUMP_FLT_MAX) +#define MIN_ROUGHNESS 0.01 + +struct BDRFPerLightData +{ + float3 H; + float3 L; + + float3 lightColor; + float distanceAttenuation; + float3 shadowColor; + float3 correctedLightColor; + + float rawNdotL; + float correctedRawNdotL; + float NdotL; + float TdotL; + float BdotL; + + float NdotH; + float TdotH; + float BdotH; + + float VdotH; + float LdotH; + float LdotH_2; + + float LdotV; + + float3 F; + float3 kS; + float3 kD; +}; + +struct BDRFCommonData +{ + float3 N; + float3 T; + float3 B; + float3 V; + + float NdotV; + float TdotV; + float BdotV; + + float metallic; + float smoothness; + float roughness; + float roughness_2; + float cubeLod; + + float3 F0; + + float2 mainUV; + + float3 positionWS; + float2 normalizedScreenSpaceUV; +}; + +float D_GGX_Anisotropic(float NoH, const float3 h, + const float3 t, const float3 b, float at, float ab) { + + //TODO: Pass TdotH and BdotH through parameters + float ToH = dot(t, h); + float BoH = dot(b, h); + float a2 = at * ab; + float3 v = float3(ab * ToH, at * BoH, a2 * NoH); + float v2 = dot(v, v); + float w2 = a2 / v2; + return a2 * w2 * w2 * (1.0 / ALLIN13DSHADER_PI); +} + +float V_SmithGGXCorrelated_Anisotropic(float at, float ab, float ToV, float BoV, + float ToL, float BoL, float NoV, float NoL) { + float lambdaV = NoL * length(float3(at * ToV, ab * BoV, NoV)); + float lambdaL = NoV * length(float3(at * ToL, ab * BoL, NoL)); + float v = 0.5 / (lambdaV + lambdaL); + return saturateMediump(v); +} +/************/ + +float DistributionGGX(float a, float NdotH) +{ + float a2 = max(a*a, MIN_ROUGHNESS * MIN_ROUGHNESS); + float NdotH2 = NdotH*NdotH; + + float num = a2; + float denom = (NdotH2 * (a2 - 1.0) + 1.0); + denom = ALLIN13DSHADER_PI * denom * denom; + + return num / denom; +} + +float GeometrySchlickGGX(float NdotV, float roughness) +{ + float r = (roughness + 1.0); + float k = (r*r) / 8.0; + + float num = NdotV; + float denom = NdotV * (1.0 - k) + k; + + return num / denom; +} + +float GeometrySmith(float NdotV, float NdotL, float roughness) +{ + float ggx2 = GeometrySchlickGGX(NdotV, roughness); + float ggx1 = GeometrySchlickGGX(NdotL, roughness); + + return ggx1 * ggx2; +} + +float3 fresnelSchlick(float3 F0, float VdotH) +{ + float OneMinusVdotH = 1 - VdotH; + float OneMinusVdotH_5 = OneMinusVdotH * OneMinusVdotH * OneMinusVdotH * OneMinusVdotH * OneMinusVdotH; + return F0 + (1.0 - F0) * OneMinusVdotH_5; +} + +float3 fresnelSchlickRoughness(float cosTheta, float3 F0, float roughness) +{ + float oneMinusRoughness = 1.0 - roughness; + float oneMinusCosTheta = 1.0 - cosTheta; + + return F0 + (max(oneMinusRoughness, F0) - F0) * pow(clamp(oneMinusCosTheta, 0.0, 1.0), 5.0); +} + +inline float3 FresnelLerp (float3 F0, float3 F90, float cosA) +{ + float t = Pow_5 (1 - cosA); // ala Schlick interpoliation + return lerp (F0, F90, t); +} + +//Cook Torrance +float3 SpecularTerm(float a, float roughness, float3 F, float NdotH, float NdotV, float NdotL, float VdotH) +{ + float D = DistributionGGX(a, NdotH); + float G = GeometrySmith(NdotV, NdotL, roughness); + float3 numerator = 4.0 * D * G * F; + + float denominator = 4 * NdotV * NdotL; + denominator = max(denominator, 0.0001); + + float3 res = numerator / denominator; + return res; +} + + +float3 SpecularAnisoTerm( + float at, float ab, + float3 F, + float NdotH, float NdotV, float NdotL, + float TdotV, float BdotV, + float TdotL, float BdotL, + float TdotH, float BdotH, + float3 H, float3 T, float3 B) +{ + float D = D_GGX_Anisotropic(NdotH, H, T, B, at, ab); + float V = V_SmithGGXCorrelated_Anisotropic( + at, ab, + TdotV, BdotV, + TdotL, BdotL, + NdotV, NdotL); + + float3 res = D * V * F; + + return res; +} + +float3 SpecularIBL(float3 positionWS, float2 normalizedScreenSpaceUV, float3 normalWS, float3 viewDirWS, float cubeLod) +{ + float3 res = 0; + +#ifdef REFLECTIONS_ON + res = GetSkyColor(positionWS, normalizedScreenSpaceUV, normalWS, viewDirWS, cubeLod); +#endif + return res; +} + +float3 DiffuseTerm(float LdotH, float LdotV, float NdotL, float roughness, float3 colorDiffuse) +{ + float LdotH_2 = LdotH * LdotH; + + float f0 = 1.0; + float f90 = 0.5 + 2*(roughness * LdotH_2); + + float3 fDiffuse = lerp(f0, f90, NdotL) * lerp(f0, f90, LdotV); + + float3 res = (colorDiffuse / ALLIN13DSHADER_PI) * fDiffuse; + return res; +} + +float3 DiffuseTerm02(float NdotV, float NdotL, float LdotH, float perceptualRoughness, float3 albedo) +{ + float fd90 = 0.5 + 2 * LdotH * LdotH * perceptualRoughness; + // Two schlick fresnel term + float lightScatter = (1 + (fd90 - 1) * Pow_5(1 - NdotL)); + float viewScatter = (1 + (fd90 - 1) * Pow_5(1 - NdotV)); + + float3 res = (albedo /*/ ALLIN13DSHADER_PI*/) * lightScatter * viewScatter; + return res; +} + +float3 IndirectLighting(float3 albedo, float3 specularColor, EffectsData effectsData, BDRFCommonData commonData, AllIn1GI gi) +{ + float3 N = commonData.N; + float3 V = commonData.V; + + //float3 ambientColor = GetAmbientColor(effectsData); + float3 diffuse = gi.diffuse * albedo; + + float3 F = fresnelSchlickRoughness(commonData.NdotV, commonData.F0, commonData.roughness); + float3 kS = F; + float3 specular = 0; +#ifdef REFLECTIONS_ON + float3 specularIBL = SpecularIBL(commonData.positionWS, commonData.normalizedScreenSpaceUV, N, V, commonData.cubeLod); + + //float reflectionLuminance = GetLuminance(float4(specularIBL, 1.0)); + //specularIBL = lerp(diffuse, specularIBL, smoothstep(0.0, 0.1, reflectionLuminance * (1 - commonData.roughness))); + + //TODO: Intermediate _Metallic values looks weird + float F_factor = 1 - commonData.metallic; + specular = specularIBL * lerp(1.0, F, F_factor); +#else + specular = lerp(diffuse * 0.25, diffuse, (1 - commonData.roughness)); +#endif + + float3 kD = 1.0 - kS; + kD *= 1.0 - commonData.metallic; + + float3 indirectDiffuse = kD * diffuse; + + //TODO: Some problems with specularColor + float3 indirectSpecular = specular * specularColor; + + + float3 res = indirectDiffuse + indirectSpecular; + + return res; +} + + +float3 DirectDiffuse_PBR(float3 albedo, BDRFCommonData commonData, BDRFPerLightData perLightData, AllIn1LightData lightData) +{ + float3 diffuseTerm = DiffuseTerm02(commonData.NdotV, perLightData.NdotL, perLightData.LdotH, commonData.roughness, albedo); + + float correctedNdotL = saturate(perLightData.correctedRawNdotL); + float3 directDiffuse = 0; +#if defined(_LIGHTMODEL_CLASSIC) + directDiffuse = diffuseTerm * perLightData.kD * perLightData.correctedLightColor * correctedNdotL; +#elif defined(_LIGHTMODEL_HALFLAMBERT) + float NdotL = saturate(perLightData.correctedRawNdotL); + float halfLambertTerm = (NdotL * ACCESS_PROP_FLOAT(_HalfLambertWrap)) + (1 - ACCESS_PROP_FLOAT(_HalfLambertWrap)); + float halfLambertTerm_2 = halfLambertTerm * halfLambertTerm; + directDiffuse = diffuseTerm * halfLambertTerm_2 * perLightData.correctedLightColor; +#elif defined(_LIGHTMODEL_FAKEGI) + float fakeGI = (correctedNdotL * ACCESS_PROP_FLOAT(_HardnessFakeGI)) + 1.0 - ACCESS_PROP_FLOAT(_HardnessFakeGI); + directDiffuse = diffuseTerm * fakeGI * perLightData.correctedLightColor; +#elif defined(_LIGHTMODEL_TOON) + directDiffuse = diffuseTerm * perLightData.kD * perLightData.correctedLightColor * correctedNdotL; + float toonFactor = smoothstep(ACCESS_PROP_FLOAT(_ToonCutoff), ACCESS_PROP_FLOAT(_ToonCutoff) + ACCESS_PROP_FLOAT(_ToonSmoothness), correctedNdotL); + directDiffuse *= toonFactor; +#elif defined(_LIGHTMODEL_TOONRAMP) + float3 rampLight = SAMPLE_TEX2D_LOD(_ToonRamp, float4((perLightData.correctedRawNdotL * 0.5) + 0.5, 0, 0, 0)).rgb; + directDiffuse = diffuseTerm * perLightData.kD * perLightData.correctedLightColor * rampLight; + //float diffuseTermLuminance = GetLuminance(directDiffuse); + //directDiffuse = SAMPLE_TEX2D(_ToonRamp, float2(diffuseTermLuminance, diffuseTermLuminance)).rgb; +#endif + + return directDiffuse; +} + +#ifdef SPECULAR_ON +float3 DirectSpecular_PBR(float3 specularColor, BDRFCommonData commonData, BDRFPerLightData perLightData, AllIn1LightData lightData, float4 specularMap) +{ + float3 specularTerm = 0; + + //float4 specularMap = SAMPLE_TEX2D(_SpecularMap, commonData.mainUV); + + #if defined(_SPECULARMODEL_CLASSIC) + specularTerm = SpecularTerm(commonData.roughness_2, commonData.roughness, perLightData.F, perLightData.NdotH, commonData.NdotV, perLightData.NdotL, perLightData.VdotH); + #elif defined(_SPECULARMODEL_TOON) + specularTerm = SpecularTerm(commonData.roughness_2, commonData.roughness, perLightData.F, perLightData.NdotH, commonData.NdotV, perLightData.NdotL, perLightData.VdotH); + specularTerm = smoothstep(ACCESS_PROP_FLOAT(_SpecularToonCutoff), ACCESS_PROP_FLOAT(_SpecularToonCutoff) + ACCESS_PROP_FLOAT(_SpecularToonSmoothness), specularTerm); + #elif defined(_SPECULARMODEL_ANISOTROPIC) || defined(_SPECULARMODEL_ANISOTROPICTOON) + //https://google.github.io/filament/Filament.html?utm_source=chatgpt.com#materialsystem/anisotropicmodel + float aniso = ACCESS_PROP_FLOAT(_Anisotropy); + float at = max((1 - ACCESS_PROP_FLOAT(_AnisoShininess)) * (1.0 + aniso), 0.001); + float ab = max((1 - ACCESS_PROP_FLOAT(_AnisoShininess)) * (1.0 - aniso), 0.001); + + specularTerm = SpecularAnisoTerm(at, ab, perLightData.F, + perLightData.NdotH, commonData.NdotV, perLightData.NdotL, + commonData.TdotV, commonData.BdotV, perLightData.TdotL, + perLightData.BdotL, perLightData.TdotH, perLightData.BdotH, + perLightData.H, commonData.T, commonData.B); + specularTerm = saturate(specularTerm); + + #if defined(_SPECULARMODEL_ANISOTROPICTOON) + float specularSmoothness = max(ACCESS_PROP_FLOAT(_SpecularToonSmoothness), 0.001); + specularTerm = smoothstep(ACCESS_PROP_FLOAT(_SpecularToonCutoff), ACCESS_PROP_FLOAT(_SpecularToonCutoff) + specularSmoothness, specularTerm); + #endif + #endif + + specularTerm *= specularMap.r; + + float3 directSpecular = specularTerm * specularColor * ACCESS_PROP_FLOAT(_SpecularAtten) * perLightData.correctedLightColor * perLightData.NdotL; + return directSpecular; +} +#endif + +float3 DirectLighting_PBR(float3 albedo, BDRFCommonData commonData, BDRFPerLightData perLightData, AllIn1LightData lightData, float4 specularMap) +{ + float3 diffuseTerm = DirectDiffuse_PBR(albedo, commonData, perLightData, lightData); + + float3 specularColor = lerp(1.0, albedo, commonData.metallic); + + float3 specularTerm = 0; +#ifdef SPECULAR_ON + specularTerm = DirectSpecular_PBR(specularColor, commonData, perLightData, lightData, specularMap); +#endif + + float3 directLight = diffuseTerm + specularTerm; + return directLight; +} + +BDRFCommonData CreateCommonBDRFData(float3 albedo, EffectsData effectsData) +{ + BDRFCommonData res; + + res.N = effectsData.normalWS; + res.T = effectsData.tangentWS; + res.B = effectsData.bitangentWS; + res.V = normalize(_WorldSpaceCameraPos.xyz - effectsData.vertexWS); + + res.metallic = effectsData.metallic; + float smoothness = effectsData.smoothness; +#ifdef _METALLIC_MAP_ON + float4 metallicMapColor = SAMPLE_TEX2D(_MetallicMap, effectsData.mainUV); + + float metallicMapValue = metallicMapColor.r; + res.metallic *= metallicMapValue; + res.metallic = saturate(res.metallic); + + float glossMapValue = metallicMapColor.a; + smoothness *= glossMapValue; + smoothness = saturate(smoothness); +#endif + + res.smoothness = lerp(0, 0.95, smoothness); + + res.roughness = (1 - res.smoothness); + res.roughness_2 = res.roughness * res.roughness; + res.cubeLod = res.roughness * 8; + + res.NdotV = max(dot(res.N, res.V), 0.0); + res.TdotV = max(dot(res.T, res.V), 0.0); + res.BdotV = max(dot(res.B, res.V), 0.0); + + + float3 f0 = 0.04; + f0 = lerp(f0, albedo, res.metallic); + + res.F0 = f0; + + res.mainUV = effectsData.mainUV; + + res.positionWS = effectsData.vertexWS; + res.normalizedScreenSpaceUV = effectsData.normalizedScreenSpaceUV; + + return res; +} + +BDRFPerLightData CreatePerLightData(BDRFCommonData commonData, AllIn1LightData lightData, float isAdditionalLight) +{ + BDRFPerLightData res; + + float oneMinusMetallic = 1 - commonData.metallic; + + res.L = lightData.lightDir; + + res.lightColor = lightData.lightColor.rgb; + res.distanceAttenuation = lightData.distanceAttenuation; + res.shadowColor = lightData.shadowColor.rgb; + res.correctedLightColor = lightData.lightColor.rgb * lightData.distanceAttenuation * lightData.shadowColor.rgb; + + res.H = normalize(commonData.V + res.L); + + res.NdotH = max(dot(commonData.N, res.H), 0.0); + res.rawNdotL = dot(commonData.N, res.L); + res.correctedRawNdotL = res.rawNdotL; + #if !defined(FORWARD_ADD_PASS) + #if defined(_LIGHTMODEL_HALFLAMBERT) || defined(_LIGHTMODEL_FAKEGI) || defined(_LIGHTMODEL_TOONRAMP) + res.correctedLightColor = isAdditionalLight > 0 ? res.correctedLightColor : res.lightColor; + res.correctedRawNdotL = isAdditionalLight > 0 ? res.correctedRawNdotL : res.correctedRawNdotL * GetLuminance(lightData.shadowColor.rgb); + #endif + #endif + + res.NdotL = max(res.rawNdotL, 0.0); + res.TdotL = max(dot(commonData.T, res.L), 0.0); + res.BdotL = max(dot(commonData.B, res.L), 0.0); + + res.VdotH = max(dot(commonData.V, res.H), 0.0); + res.TdotH = max(dot(commonData.T, res.H), 0.0); + res.BdotH = max(dot(commonData.B, res.H), 0.0); + + res.LdotV = max(dot(res.L, commonData.V), 0.0); + res.LdotH = max(dot(res.L, res.H), 0.0); + + res.LdotH_2 = res.LdotH * res.LdotH; + + res.F = fresnelSchlick(commonData.F0, res.VdotH); + res.kS = res.F; + res.kD = (1.0 - res.kS) * oneMinusMetallic; + + return res; +} + +float3 CalculateLighting_PBR(float3 albedo, float alpha, EffectsData effectsData, AllIn1GI gi) +{ + BDRFCommonData commonData = CreateCommonBDRFData(albedo, effectsData); + + float3 specularColor = lerp(1.0, albedo, commonData.metallic); + + AllIn1LightData mainLightData = GetMainLightData(effectsData.vertexWS, effectsData, gi); + + + float3 directLighting = albedo; + float4 specularMap = float4(1, 1, 1, 1); + + +#ifdef ALLIN1_USE_LIGHT_LAYERS + uint meshRenderingLayers = AllIn1GetMeshRenderingLayer(); + directLighting = 0; + if (IsMatchingLightLayer(mainLightData.layerMask, meshRenderingLayers)) + { + directLighting = albedo; +#endif + BDRFPerLightData perLightData_mainLight = CreatePerLightData(commonData, mainLightData, 0.0); + +#ifdef SPECULAR_ON + specularMap = SAMPLE_TEX2D(_SpecularMap, commonData.mainUV); +#endif + + directLighting = DirectLighting_PBR(albedo, commonData, perLightData_mainLight, mainLightData, specularMap); + +#ifdef ALLIN1_USE_LIGHT_LAYERS + } +#endif + +#if defined(ADDITIONAL_LIGHT_LOOP) && !defined(_LIGHTMODEL_FASTLIGHTING) + // Additional light loop for non-main directional lights. This block is specific to Forward+. + #if USE_CLUSTER_LIGHT_LOOP + UNITY_LOOP for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++) + { + AllIn1LightData additionalLightData = GetPointLightData(lightIndex, effectsData.vertexWS, effectsData.normalWS, effectsData, gi); + #ifdef ALLIN1_USE_LIGHT_LAYERS + if (IsMatchingLightLayer(additionalLightData.layerMask, meshRenderingLayers)) + { + #endif + BDRFPerLightData perLightData_additionalLight = CreatePerLightData(commonData, additionalLightData, 1.0); + directLighting += DirectLighting_PBR(albedo, commonData, perLightData_additionalLight, additionalLightData, specularMap); + #ifdef ALLIN1_USE_LIGHT_LAYERS + } + #endif + } + #endif + + + uint numAdditionalLights = NUM_ADDITIONAL_LIGHTS; + LIGHT_LOOP_BEGIN_ALLIN13D(numAdditionalLights, effectsData) + AllIn1LightData additionalLightData = GetPointLightData(lightIndex, effectsData.vertexWS, effectsData.normalWS, effectsData, gi); + #ifdef ALLIN1_USE_LIGHT_LAYERS + + uint meshRenderingLayers = AllIn1GetMeshRenderingLayer(); + if (IsMatchingLightLayer(additionalLightData.layerMask, meshRenderingLayers)) + { + #endif + BDRFPerLightData perLightData_additionalLight = CreatePerLightData(commonData, additionalLightData, 1.0); + directLighting += DirectLighting_PBR(albedo, commonData, perLightData_additionalLight, additionalLightData, specularMap); + + #ifdef ALLIN1_USE_LIGHT_LAYERS + } + #endif + + LIGHT_LOOP_END_ALLIN13D +#endif + + float2 ssaoFactor = GetSSAO(effectsData.normalizedScreenSpaceUV.xy, alpha); + + float3 res = directLighting * ssaoFactor.x; + + + + //We add IndirectLighting only once +#ifndef FORWARD_ADD_PASS + #if defined(_CUSTOM_SHADOW_COLOR_ON) + float shadowT = saturate(mainLightData.realtimeShadow + 1.0 - global_shadowColor.a); + res = lerp(global_shadowColor, res, shadowT); + #endif + + float3 ao = 1.0; + #ifdef _AOMAP_ON + ao = GetAOMapTerm(effectsData.mainUV); + #endif + + float3 indirectLighting = IndirectLighting(albedo, specularColor, effectsData, commonData, gi); + res += (indirectLighting) * ao * ssaoFactor.y; +#endif + + return res; +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BRDF.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BRDF.hlsl.meta new file mode 100644 index 0000000..89f4099 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BRDF.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 48d6d644a14e13f469715bc1a7d738df +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BRDF.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BasePass.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BasePass.hlsl new file mode 100644 index 0000000..2f9b114 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BasePass.hlsl @@ -0,0 +1,252 @@ +#ifndef ALLIN13DSHADER_BASE_PASS_INCLUDED +#define ALLIN13DSHADER_BASE_PASS_INCLUDED + +FragmentData BasicVertex(VertexData v) +{ + FragmentData o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#ifdef _SPHERIZE_NORMALS_ON + float3 normalOS = normalize(v.vertex); +#else + float3 normalOS = v.normal; +#endif + + o.interpolator_01 = 0; + +#ifdef _USE_CUSTOM_TIME + SHADER_TIME(o) = allIn13DShader_globalTime.xyz + ACCESS_PROP_FLOAT(_TimingSeed); +#else + SHADER_TIME(o) = _Time.xyz + ACCESS_PROP_FLOAT(_TimingSeed); +#endif + + float3 originalVertex = v.vertex.xyz; + + v.vertex = ApplyVertexEffects(v.vertex, normalOS, SHADER_TIME(o)); +#ifdef _RECALCULATE_NORMALS_ON + float3 tangentNeighbour = originalVertex + normalize(v.tangent.xyz) * RECALCULATE_NORMAL_OFFSET; + float3 bitangent = normalize(cross(v.normal, v.tangent.xyz)); + float3 bitangentNeightbour = originalVertex + bitangent * RECALCULATE_NORMAL_OFFSET; + + tangentNeighbour = ApplyVertexEffects(float4(tangentNeighbour, 1.0), normalOS, SHADER_TIME(o)).xyz; + bitangentNeightbour = ApplyVertexEffects(float4(bitangentNeightbour, 1.0), normalOS, SHADER_TIME(o)).xyz; + + float3 correctedTangent = normalize(tangentNeighbour - v.vertex.xyz); + float3 correctedBitangent = normalize(bitangentNeightbour - v.vertex.xyz); + + v.tangent = float4(correctedTangent, v.tangent.w); + normalOS = normalize(cross(correctedTangent, correctedBitangent)); +#endif + + + POSITION_OS(o) = v.vertex.xyz; + NORMAL_OS(o) = normalOS; + POSITION_WS(o) = GetPositionWS(v.vertex); + + o.normalWS = GetNormalWS(normalOS); + + o.pos = OBJECT_TO_CLIP_SPACE(v); + + + + VIEWDIR_WS(o) = GetViewDirWS(POSITION_WS(o)); + + float4 projPos = 0; + + +#if defined(REQUIRE_SCREEN_POS) + o.projPos = ComputeScreenPos(o.pos); + + #if defined(REQUIRE_SCENE_DEPTH) + o.projPos.z = ComputeEyeDepth(POSITION_WS(o)); + #endif + + projPos = o.projPos; +#endif + + float2 uv = v.uv; + uv = ApplyUVEffects_VertexStage(uv, POSITION_WS(o), projPos, SHADER_TIME(o)); + + UV_DIFF(o) = uv - v.uv; + + SCALED_MAIN_UV(o) = CUSTOM_TRANSFORM_TEX(v.uv, UV_DIFF(o), _MainTex); + RAW_MAIN_UV(o) = uv; + + o.interpolator_02 = 0; + + +#if defined(REQUIRE_TANGENT_WS) + float3 tangentWS = GetDirWS(float4(v.tangent.xyz, 0)); + float3 bitangentWS = GetBitangentWS(v.tangent, tangentWS, o.normalWS); + INIT_T_SPACE(o.normalWS) + + UV_NORMAL_MAP(o) = CUSTOM_TRANSFORM_TEX(v.uv, UV_DIFF(o), _NormalMap); +#endif + + ShadowCoordStruct shadowCoordStruct = GetShadowCoords(v, o.pos, POSITION_WS(o), v.uvLightmap); + o._ShadowCoord = shadowCoordStruct._ShadowCoord; + +#ifdef LIGHTMAP_ON + UV_LIGHTMAP(o) = v.uvLightmap * unity_LightmapST.xy + unity_LightmapST.zw; +#else + UV_LIGHTMAP(o) = v.uvLightmap; +#endif + FOGCOORD(o) = GetFogFactor(o.pos); + +#ifdef _EMISSION_ON + UV_EMISSION_MAP(o) = SIMPLE_CUSTOM_TRANSFORM_TEX(v.uv, _EmissionMap); +#endif + + + //Vertex Color initialization + VERTEX_COLOR_R(o) = v.vertexColor.r; + VERTEX_COLOR_G(o) = v.vertexColor.g; + VERTEX_COLOR_B(o) = v.vertexColor.b; + VERTEX_COLOR_A(o) = v.vertexColor.a; + + return o; +} + +float4 BasicFragment( + FragmentData i + #ifdef _WRITE_RENDERING_LAYERS + #if UNITY_VERSION >= 60020000 + , out uint outRenderingLayers : SV_Target1 + #else + , out float4 outRenderingLayers : SV_Target1 + #endif + #endif + ) : SV_Target +{ + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + #if defined(LOD_FADE_CROSSFADE) + ALLIN1_APPLY_CROSSFADE(i) + #endif + + AllIn1DecalData decalData; + INIT_DECAL_DATA(decalData); + +#ifdef ALLIN1_DECALS_READY_TO_USE + ConfigureDecalData(decalData, i.pos); +#endif + + +#if defined(_FLAT_NORMALS_ON) + i.normalWS = GetFlatNormalWS(i.normalWS, POSITION_WS(i)); + #if defined(REQUIRE_TANGENT_WS) + i.tspace0 = float3(i.tspace0.x, i.tspace0.y, i.normalWS.x); + i.tspace1 = float3(i.tspace1.x, i.tspace1.y, i.normalWS.y); + i.tspace2 = float3(i.tspace2.x, i.tspace2.y, i.normalWS.z); + #endif +#endif + + EffectsData data = CalculateEffectsData(i, decalData); + + data = ApplyUVEffects_FragmentStage(data); + + + data.normalWS = GetNormalWS(data, i, decalData); + + + +#ifdef _NORMAL_MAP_ON + data.bitangentWS = normalize(cross(data.normalWS, data.tangentWS)); +#endif + + float4 objectColor = GetBaseColor(data); + + float3 normalOS = data.normalOS; + float3 normalWS = data.normalWS; + float3 viewDirWS = data.viewDirWS; + + float sceneDepthDiff = 1.0; + float normalizedDepth = 0; +#ifdef REQUIRE_SCENE_DEPTH + sceneDepthDiff = GetSceneDepthDiff(i.projPos); + normalizedDepth = GetNormalizedDepth(i.projPos); +#endif + + float camDistance = 0; +#ifdef REQUIRE_CAM_DISTANCE + camDistance = distance(POSITION_WS(i), _WorldSpaceCameraPos); +#endif + + objectColor *= ACCESS_PROP_FLOAT4(_Color); + objectColor = ApplyColorEffectsBeforeLighting(objectColor, data); + +#ifdef ALLIN1_DECALS_READY_TO_USE + objectColor.rgb = objectColor.rgb * decalData.baseColor.a + decalData.baseColor.rgb; +#endif + + float4 col = objectColor; + + + + AllIn1GI gi = CalculateGI(UV_LIGHTMAP(i), data); + float3 lightmap = GetLightmap(UV_LIGHTMAP(i), data); +#if defined(_AFFECTED_BY_LIGHTMAPS_ON) && defined(_LIGHTMAP_COLOR_CORRECTION_ON) + lightmap = LightmapColorCorrection(lightmap); +#endif + + + float3 ambientColor = GetAmbientColor(data); + +#ifdef LIGHT_ON + float3 mainLightColor = GetMainLightColorRGB(); + float3 mainLightDir = GetMainLightDir(POSITION_WS(i)); + + col.rgb = CalculateLighting( + POSITION_WS(i), + normalWS, data.tangentWS, data.bitangentWS, + objectColor.rgb, objectColor.a, + 1.0, ambientColor, viewDirWS, + SCALED_MAIN_UV(i), mainLightColor, mainLightDir, i, 1.0, data, + gi); +#else + float2 ssaoFactor = GetSSAO(data.normalizedScreenSpaceUV.xy, objectColor.a); + col.rgb = IndirectLighting_Basic(objectColor.rgb, ssaoFactor, data, gi); +#endif + +#ifdef _EMISSION_ON + float2 emissionUV = SIMPLE_CUSTOM_TRANSFORM_TEX(MAIN_UV(data), _EmissionMap); + float4 emissionMapCol = SAMPLE_TEX2D(_EmissionMap, emissionUV); + float4 emissionCol = emissionMapCol * ACCESS_PROP_FLOAT4(_EmissionColor) * ACCESS_PROP_FLOAT(_EmissionSelfGlow); + + emissionCol.rgb += decalData.emissive; + + col.rgb += emissionCol.rgb; +#endif + + col = ApplyAlphaEffects(col, + SCALED_MAIN_UV(i), UV_LIGHTMAP(i), data.vertexWS, + sceneDepthDiff, data.camDistance, data.projPos); + +#ifdef _ALPHA_CUTOFF_ON + clip((col.a - ACCESS_PROP_FLOAT(_AlphaCutoffValue)) - 0.001); +#endif + + col = ApplyColorEffectsAfterLighting(col, data); + col.a *= ACCESS_PROP_FLOAT(_GeneralAlpha); + +#if defined(FOG_ENABLED) + col = CustomMixFog(FOGCOORD(i), col); +#endif + +#if defined(_WRITE_RENDERING_LAYERS) + #if UNITY_VERSION >= 60020000 + outRenderingLayers = EncodeMeshRenderingLayer(); + #else + uint renderingLayers = AllIn1GetMeshRenderingLayer(); + outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0); + #endif +#endif + + return col; +} + +#endif /*ALLIN13DSHADER_BASE_PASS_INCLUDED*/ \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BasePass.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BasePass.hlsl.meta new file mode 100644 index 0000000..f12ac39 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BasePass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 3f95914655851fb429e79f8b41ef5cf0 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BasePass.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BufferPropertiesDeclaration.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BufferPropertiesDeclaration.hlsl new file mode 100644 index 0000000..3b81c3c --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BufferPropertiesDeclaration.hlsl @@ -0,0 +1,364 @@ +#ifndef ALLIN13DSHADER_BUFFERPROPERTIESDECLARATION +#define ALLIN13DSHADER_BUFFERPROPERTIESDECLARATION + +DECLARE_PROPERTY_FLOAT4(_MainTex_ST) +DECLARE_PROPERTY_FLOAT4(_Color) +DECLARE_PROPERTY_FLOAT(_GeneralAlpha) +DECLARE_PROPERTY_FLOAT(_TimingSeed) + +#if defined(REQUIRE_TANGENT_WS) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_NormalMap_ST) + DECLARE_PROPERTY_FLOAT(_NormalStrength) + #if defined(_TRIPLANAR_MAPPING_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_TopNormalStrength) + #endif +#endif + +#if defined(_FLAT_NORMALS_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_FlatNormalsBlend) +#endif + +#if defined(_SHADINGMODEL_PBR) || defined(_SPECULARMODEL_ANISOTROPIC) || defined(_SPECULARMODEL_ANISOTROPICTOON) || defined(ALWAYS_DECLARE_PROPERTY) + #define HAS_PBR_PROPERTIES + DECLARE_PROPERTY_FLOAT(_Metallic) + DECLARE_PROPERTY_FLOAT(_Smoothness) +#endif + +#if defined(_LIGHTMODEL_TOON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_ToonCutoff) + DECLARE_PROPERTY_FLOAT(_ToonSmoothness) +#endif + +#if defined(_LIGHTMODEL_HALFLAMBERT) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_HalfLambertWrap) +#endif + +#if defined(_LIGHTMODEL_FAKEGI) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_HardnessFakeGI) +#endif + +#if defined(SPECULAR_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_SpecularAtten) + DECLARE_PROPERTY_FLOAT(_Shininess) + + DECLARE_PROPERTY_FLOAT(_Anisotropy) + DECLARE_PROPERTY_FLOAT(_AnisoShininess) +#endif + +#if (defined(_AFFECTED_BY_LIGHTMAPS_ON) && defined(_LIGHTMAP_COLOR_CORRECTION_ON)) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_HueShiftLM) + DECLARE_PROPERTY_FLOAT(_HueSaturationLM) + DECLARE_PROPERTY_FLOAT(_HueBrightnessLM) + DECLARE_PROPERTY_FLOAT(_ContrastLM) + DECLARE_PROPERTY_FLOAT(_BrightnessLM) +#endif + +#if defined(_RECEIVE_SHADOWS_ON) + DECLARE_PROPERTY_FLOAT(_ShadowCutoff) +#endif + +#if defined(_CUSTOM_AMBIENT_LIGHT_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_CustomAmbientColor) +#endif + +#if defined(_SPECULARMODEL_TOON) || defined(_SPECULARMODEL_ANISOTROPICTOON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_SpecularToonCutoff) + DECLARE_PROPERTY_FLOAT(_SpecularToonSmoothness) +#endif + +#if defined(_AOMAP_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_AOMap_ST) + DECLARE_PROPERTY_FLOAT(_AOMapStrength) + DECLARE_PROPERTY_FLOAT(_AOContrast) + DECLARE_PROPERTY_FLOAT4(_AOColor) +#endif + +#if defined(REFLECTIONS_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_ReflectionsAtten) + #if defined(_REFLECTIONS_TOON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_ToonFactor) + #endif +#endif + +#if defined(_CONTRAST_BRIGHTNESS_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_Contrast) + DECLARE_PROPERTY_FLOAT(_Brightness) +#endif + +#if defined(_HEIGHT_GRADIENT_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_MinGradientHeight) + DECLARE_PROPERTY_FLOAT(_MaxGradientHeight) + DECLARE_PROPERTY_FLOAT4(_GradientHeightColor01) + DECLARE_PROPERTY_FLOAT4(_GradientHeightColor02) +#endif + +#if defined(_INTERSECTION_GLOW_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_DepthGlowDist) + DECLARE_PROPERTY_FLOAT(_DepthGlowPower) + DECLARE_PROPERTY_FLOAT4(_DepthGlowColor) + DECLARE_PROPERTY_FLOAT(_DepthGlowColorIntensity) + DECLARE_PROPERTY_FLOAT(_DepthGlowGlobalIntensity) +#endif + +#if defined(_INTERSECTION_FADE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_IntersectionFadeFactor) +#endif + +#if defined(_HIGHLIGHTS_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_HighlightsColor) + DECLARE_PROPERTY_FLOAT(_HighlightsStrength) + DECLARE_PROPERTY_FLOAT(_HighlightCutoff) + DECLARE_PROPERTY_FLOAT(_HighlightSmoothness) + DECLARE_PROPERTY_FLOAT3(_HighlightOffset) +#endif + +#if defined(_RIM_LIGHTING_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_RimColor) + DECLARE_PROPERTY_FLOAT(_RimAttenuation) + DECLARE_PROPERTY_FLOAT(_MinRim) + DECLARE_PROPERTY_FLOAT(_MaxRim) + DECLARE_PROPERTY_FLOAT3(_RimOffset) +#endif + +#if defined(_HUE_SHIFT_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_HueShift) + DECLARE_PROPERTY_FLOAT(_HueSaturation) + DECLARE_PROPERTY_FLOAT(_HueBrightness) +#endif + +#if defined(_HIT_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_HitColor) + DECLARE_PROPERTY_FLOAT(_HitGlow) + DECLARE_PROPERTY_FLOAT(_HitBlend) +#endif + +#if defined(_STOCHASTIC_SAMPLING_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_StochasticScale) + DECLARE_PROPERTY_FLOAT(_StochasticSkew) +#endif + +#if defined(_VERTEX_SHAKE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_ShakeSpeed) + DECLARE_PROPERTY_FLOAT(_ShakeSpeedMult) + DECLARE_PROPERTY_FLOAT4(_ShakeMaxDisplacement) + DECLARE_PROPERTY_FLOAT(_ShakeBlend) +#endif + +#if defined(_FADE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_FadeTex_ST) + DECLARE_PROPERTY_FLOAT(_FadeAmount) + DECLARE_PROPERTY_FLOAT(_FadePower) + DECLARE_PROPERTY_FLOAT(_FadeTransition) + #if defined(_FADE_BURN_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_FadeBurnColor) + DECLARE_PROPERTY_FLOAT(_FadeBurnWidth) + DECLARE_PROPERTY_FLOAT(_BurnCutoff) + DECLARE_PROPERTY_FLOAT(_BurnSmoothness) + #endif +#endif + +#if defined(_FADE_BY_CAM_DISTANCE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_MinDistanceToFade) + DECLARE_PROPERTY_FLOAT(_MaxDistanceToFade) +#endif + +#if defined(_DITHER_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_DitherScale) +#endif + +#if defined(_VERTEX_INFLATE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_MinInflate) + DECLARE_PROPERTY_FLOAT(_MaxInflate) + DECLARE_PROPERTY_FLOAT(_InflateBlend) +#endif + +#if defined(_VERTEX_DISTORTION_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_VertexDistortionNoiseTex_ST) + DECLARE_PROPERTY_FLOAT(_VertexDistortionAmount) + DECLARE_PROPERTY_FLOAT(_VertexDistortionNoiseSpeedX) + DECLARE_PROPERTY_FLOAT(_VertexDistortionNoiseSpeedY) +#endif + +#if defined(_VOXELIZE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_VoxelSize) + DECLARE_PROPERTY_FLOAT(_VoxelBlend) +#endif + +#if defined(_GLITCH_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_GlitchTiling) + DECLARE_PROPERTY_FLOAT(_GlitchAmount) + DECLARE_PROPERTY_FLOAT3(_GlitchOffset) + DECLARE_PROPERTY_FLOAT(_GlitchSpeed) + DECLARE_PROPERTY_FLOAT(_GlitchWorldSpace) +#endif + +#if defined(_WIND_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_WindAttenuation) + #if defined(_USE_WIND_VERTICAL_MASK) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_WindVerticalMaskMinY) + DECLARE_PROPERTY_FLOAT(_WindVerticalMaskMaxY) + #endif +#endif + +#if defined(_COLOR_RAMP_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_ColorRampLuminosity) + DECLARE_PROPERTY_FLOAT(_ColorRampBlend) + DECLARE_PROPERTY_FLOAT(_ColorRampScrollSpeed) + DECLARE_PROPERTY_FLOAT(_ColorRampTiling) +#endif + +#if defined(_ALBEDO_VERTEX_COLOR_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_VertexColorBlending) +#endif + + + +//Texture blending properties declaration +#if defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_BlendingTextureG_ST) + DECLARE_PROPERTY_FLOAT4(_BlendingTextureB_ST) + + DECLARE_PROPERTY_FLOAT4(_BlendingTextureWhite_ST) + + DECLARE_PROPERTY_FLOAT4(_TexBlendingMask_ST) + + DECLARE_PROPERTY_FLOAT(_BlendingMaskCutoffG) + DECLARE_PROPERTY_FLOAT(_BlendingMaskSmoothnessG) + + DECLARE_PROPERTY_FLOAT(_BlendingMaskCutoffB) + DECLARE_PROPERTY_FLOAT(_BlendingMaskSmoothnessB) + + DECLARE_PROPERTY_FLOAT(_BlendingMaskCutoffWhite) + DECLARE_PROPERTY_FLOAT(_BlendingMaskSmoothnessWhite) +#else + #if defined(_TEXTURE_BLENDING_ON) + #if defined(_TEXTUREBLENDINGMODE_RGB) + DECLARE_PROPERTY_FLOAT4(_BlendingTextureG_ST) + DECLARE_PROPERTY_FLOAT4(_BlendingTextureB_ST) + #else + DECLARE_PROPERTY_FLOAT4(_BlendingTextureWhite_ST) + DECLARE_PROPERTY_FLOAT(_BlendingMaskCutoffWhite) + DECLARE_PROPERTY_FLOAT(_BlendingMaskSmoothnessWhite) + #endif + + DECLARE_PROPERTY_FLOAT(_BlendingMaskCutoffG) + DECLARE_PROPERTY_FLOAT(_BlendingMaskSmoothnessG) + + DECLARE_PROPERTY_FLOAT(_BlendingMaskCutoffB) + DECLARE_PROPERTY_FLOAT(_BlendingMaskSmoothnessB) + + #if defined(_TEXTUREBLENDINGSOURCE_TEXTURE) + DECLARE_PROPERTY_FLOAT4(_TexBlendingMask_ST) + #endif + #endif +#endif +// + +#if defined(_GREYSCALE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_GreyscaleLuminosity) + DECLARE_PROPERTY_FLOAT4(_GreyscaleTintColor) + DECLARE_PROPERTY_FLOAT(_GreyscaleBlending) +#endif + +#if defined(_POSTERIZE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_PosterizeNumColors) + DECLARE_PROPERTY_FLOAT(_PosterizeGamma) +#endif + +#if defined(_HAND_DRAWN_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_HandDrawnAmount) + DECLARE_PROPERTY_FLOAT(_HandDrawnSpeed) +#endif + +#if defined(_MATCAP_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_MatcapIntensity) + DECLARE_PROPERTY_FLOAT(_MatcapBlend) +#endif + +#if defined(_SCREEN_SPACE_UV_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_ScaleWithCameraDistance) +#endif + +#if defined(_SCROLL_TEXTURE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_ScrollTextureX) + DECLARE_PROPERTY_FLOAT(_ScrollTextureY) +#endif + +#if defined(_UV_DISTORTION_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_DistortTex_ST) + + DECLARE_PROPERTY_FLOAT(_DistortAmount) + DECLARE_PROPERTY_FLOAT(_DistortTexXSpeed) + DECLARE_PROPERTY_FLOAT(_DistortTexYSpeed) +#endif + +#if defined(_PIXELATE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_PixelateSize) + DECLARE_PROPERTY_FLOAT4(_MainTex_TexelSize) +#endif + +#if defined(_EMISSION_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_EmissionSelfGlow) + DECLARE_PROPERTY_FLOAT4(_EmissionMap_ST) + DECLARE_PROPERTY_FLOAT4(_EmissionColor) +#endif + +#if defined(_WAVE_UV_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_WaveAmount) + DECLARE_PROPERTY_FLOAT(_WaveSpeed) + DECLARE_PROPERTY_FLOAT(_WaveStrength) + DECLARE_PROPERTY_FLOAT(_WaveX) + DECLARE_PROPERTY_FLOAT(_WaveY) +#endif + +#if defined(_HOLOGRAM_ON) || defined(ALWAYS_DECLARE_PROPERTY) + + DECLARE_PROPERTY_FLOAT4(_HologramColor) + DECLARE_PROPERTY_FLOAT3(_HologramLineDirection) + DECLARE_PROPERTY_FLOAT(_HologramBaseAlpha) + + DECLARE_PROPERTY_FLOAT(_HologramScrollSpeed) + DECLARE_PROPERTY_FLOAT(_HologramFrequency) + DECLARE_PROPERTY_FLOAT(_HologramAlpha) + + DECLARE_PROPERTY_FLOAT(_HologramAccentSpeed) + DECLARE_PROPERTY_FLOAT(_HologramAccentFrequency) + DECLARE_PROPERTY_FLOAT(_HologramAccentAlpha) + + DECLARE_PROPERTY_FLOAT(_HologramLineCenter) + DECLARE_PROPERTY_FLOAT(_HologramLineSpacing) + DECLARE_PROPERTY_FLOAT(_HologramLineSmoothness) +#endif + +#if defined(_TRIPLANAR_MAPPING_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_TriplanarTopTex_ST) + DECLARE_PROPERTY_FLOAT4(_TriplanarTopNormalMap_ST) + + DECLARE_PROPERTY_FLOAT(_FaceDownCutoff) + DECLARE_PROPERTY_FLOAT(_TriplanarSharpness) + + DECLARE_PROPERTY_FLOAT4(_TriplanarNoiseTex_ST) + DECLARE_PROPERTY_FLOAT(_TriplanarTransitionPower) +#endif + +#if defined(_SUBSURFACE_SCATTERING_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_NormalInfluence) + DECLARE_PROPERTY_FLOAT(_SSSPower) + DECLARE_PROPERTY_FLOAT(_SSSFrontPower) + DECLARE_PROPERTY_FLOAT(_SSSAtten) + DECLARE_PROPERTY_FLOAT(_SSSFrontAtten) + DECLARE_PROPERTY_FLOAT4(_SSSColor) +#endif + +#if defined(_ALPHA_CUTOFF_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT(_AlphaCutoffValue) +#endif + +#if defined(OUTLINE_ON) || defined(ALWAYS_DECLARE_PROPERTY) + DECLARE_PROPERTY_FLOAT4(_OutlineColor) + DECLARE_PROPERTY_FLOAT(_OutlineThickness) + DECLARE_PROPERTY_FLOAT(_MaxCameraDistance) + DECLARE_PROPERTY_FLOAT(_MaxFadeDistance) +#endif + +#endif //ALLIN13DSHADER_BUFFERPROPERTIESDECLARATION \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BufferPropertiesDeclaration.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BufferPropertiesDeclaration.hlsl.meta new file mode 100644 index 0000000..e1912f7 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BufferPropertiesDeclaration.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: b5f70f4432d35e445a1292b96d6f55bd +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_BufferPropertiesDeclaration.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl new file mode 100644 index 0000000..54cee63 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl @@ -0,0 +1,252 @@ +#ifndef ALLIN13DSHADER_COMMON_FUNCTIONS +#define ALLIN13DSHADER_COMMON_FUNCTIONS + +#define ALLIN13DSHADER_PI 3.14159265359f +#define ALLIN13DSHADER_TWO_PI 6.28318530718f +#define ALLIN13DSHADER_FOUR_PI 12.56637061436f +#define ALLIN13DSHADER_INV_PI 0.31830988618f +#define ALLIN13DSHADER_INV_TWO_PI 0.15915494309f +#define ALLIN13DSHADER_INV_FOUR_PI 0.07957747155f +#define ALLIN13DSHADER_HALF_PI 1.57079632679f +#define ALLIN13DSHADER_INV_HALF_PI 0.636619772367f + +#define CUSTOM_TRANSFORM_TEX(uv, increment, name) ((uv.xy + increment.xy) * ACCESS_PROP_FLOAT4(name##_ST).xy/*ACCESS_PROP_TILING_AND_OFFSET(name##_ST).xy*/ + ACCESS_PROP_FLOAT4(name##_ST).zw/*ACCESS_PROP_TILING_AND_OFFSET(name##_ST).zw*/) +#define SIMPLE_CUSTOM_TRANSFORM_TEX(uv, name) uv.xy * ACCESS_PROP_FLOAT4(name##_ST).xy/*ACCESS_PROP_TILING_AND_OFFSET(name##_ST).xy*/ + /*ACCESS_PROP_FLOAT4(name##_ST).zw*/ACCESS_PROP_TILING_AND_OFFSET(name##_ST).zw + +#define DEFAULT_NORMAL_MAP_VALUE float4(1, 0.5, 0.5, 0.5) + +#ifdef _CUSTOM_SHADOW_COLOR_ON + #define SHADOW_COLOR global_shadowColor +#else + #define SHADOW_COLOR 0 +#endif + +float Pow_5(float x) +{ + float x2 = x * x; + float res = x2 * x2 * x; + return res; +} + +float EaseOutQuint(float x) +{ + return 1 - Pow_5(1 - x); +} + +float RemapFloat(float inValue, float inMin, float inMax, float outMin, float outMax) +{ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); +} + +float3 RemapFloat3(float3 inValue, float3 inMin, float3 inMax, float3 outMin, float3 outMax) +{ + float3 res = + float3 + ( + RemapFloat(inValue.x, inMin.x, inMax.x, outMin.x, outMax.x), + RemapFloat(inValue.y, inMin.y, inMax.y, outMin.y, outMax.y), + RemapFloat(inValue.z, inMin.z, inMax.z, outMin.z, outMax.z) + ); + + return res; +} + +float GetLuminanceRaw(float4 col) +{ + float res = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + res *= col.a; + return res; +} + +float GetLuminance(float4 col) +{ + return GetLuminanceRaw(col); +} + +float GetLuminance(float3 col) +{ + return GetLuminance(float4(col, 1.0)); +} + +float noise(float2 p) +{ + return frac(sin(dot(p, float2(12.9898, 78.233))) * 43758.5453); +} + +float noise2D(float2 p) +{ + float2 ip = floor(p); + float2 fp = frac(p); + fp = fp * fp * (3 - 2 * fp); + + float n00 = noise(ip); + float n01 = noise(ip + float2(0, 1)); + float n10 = noise(ip + float2(1, 0)); + float n11 = noise(ip + float2(1, 1)); + + return lerp(lerp(n00, n01, fp.y), lerp(n10, n11, fp.y), fp.x); +} + +//hash for randomness +float2 hash2D2D(float2 s) +{ + //magic numbers + return frac(sin(fmod(float2(dot(s, float2(127.1, 311.7)), dot(s, float2(269.5, 183.3))), 3.14159)) * 43758.5453); +} + +//float4x3 getStochasticOffsets(float2 uv, float scale = 3.464, float skewAmount = 0.57735027) +float4x3 getStochasticOffsets(float2 uv, float scale, float skewAmount) +{ + //triangle vertices and blend weights + //BW_vx[0...2].xyz = triangle verts + //BW_vx[3].xy = blend weights (z is unused) + float4x3 BW_vx; + + //uv transformed into triangular grid space with UV scaled by approximation of 2*sqrt(3) + float2 skewUV = mul(float2x2(1.0, 0.0, -skewAmount, 1.15470054), uv * scale); + + //vertex IDs and barycentric coords + float2 vxID = float2(floor(skewUV)); + float3 barry = float3(frac(skewUV), 0); + barry.z = 1.0 - barry.x - barry.y; + + BW_vx = ((barry.z > 0) ? + float4x3(float3(vxID, 0), float3(vxID + float2(0, 1), 0), float3(vxID + float2(1, 0), 0), barry.zyx) : + float4x3(float3(vxID + float2(1, 1), 0), float3(vxID + float2(1, 0), 0), float3(vxID + float2(0, 1), 0), float3(-barry.z, 1.0 - barry.y, 1.0 - barry.x))); + + return BW_vx; +} + +#ifdef _NORMAL_MAP_ON +float3 GetNormalWSFromNormalMap(float3 tnormal, float normalStrength, + float3 tspace0, float3 tspace1, float3 tspace2) +{ + tnormal.xy *= normalStrength; + + float3 res = 0; + res.x = dot(tspace0, tnormal); + res.y = dot(tspace1, tnormal); + res.z = dot(tspace2, tnormal); + + res = normalize(res); + + return res; +} + +//float3 GetNormalWSFromNormalMap(sampler2D normalMap, float2 uv, float normalStrength, +// float3 tspace0, float3 tspace1, float3 tspace2) +//{ +// float3 tnormal = UnpackNormal(SAMPLE_TEX2D(normalMap, uv)); + +// return GetNormalWSFromNormalMap(tnormal, normalStrength, tspace0, tspace1, tspace2); + +// //tnormal.xy *= normalStrength; + +// //float3 res = 0; +// //res.x = dot(tspace0, tnormal); +// //res.y = dot(tspace1, tnormal); +// //res.z = dot(tspace2, tnormal); + +// //res = normalize(res); + +// //return res; +//} +#endif + +float3 BlendingUnpackedNormals(float3 unpackedNormal0, float3 unpackedNormal1) +{ + float2 unpackedBlendedNormalXY = unpackedNormal0.xy + unpackedNormal1.xy; + float unpackedBlendedNormalZ = unpackedNormal0.z * unpackedNormal1.z; + + float3 res = normalize(float3(unpackedBlendedNormalXY.x, unpackedBlendedNormalXY.y, unpackedBlendedNormalZ)); + return res; +} + +#ifdef REQUIRE_SCENE_DEPTH +float ComputeEyeDepth(float3 vertexWS) +{ + float3 positionVS = mul(UNITY_MATRIX_V, float4(vertexWS, 1.0)).xyz; + float res = -positionVS.z; + + return res; +} + +float GetNormalizedDepth(float4 projPos) +{ + float nearClip = _ProjectionParams.y + global_MinDepth; + float farClip = nearClip + global_DepthZoneLength; + + float cameraRange = farClip - nearClip; + + float distanceToNearClip = projPos.z - global_MinDepth; + + float res = distanceToNearClip / cameraRange; + + res = saturate(res); + + return res; +} + +float GetEyeDepth(float3 vertexVS) +{ + return -vertexVS.z; +} + +#endif + +#ifdef _AOMAP_ON + +float3 GetAOMapTerm(float2 uv) +{ + float aoTex = SAMPLE_TEX2D(_AOMap, uv).r; + + //float ao = smoothstep(ACCESS_PROP_FLOAT(_AOContrast), 1 - ACCESS_PROP_FLOAT(_AOContrast), aoTex); + float3 ao = max(0, (aoTex - float3(0.5, 0.5, 0.5)) * ACCESS_PROP_FLOAT(_AOContrast) + float3(0.5, 0.5, 0.5)); + + ao = saturate(ao + 1 - ACCESS_PROP_FLOAT(_AOMapStrength)); + float3 res = lerp(ACCESS_PROP_FLOAT4(_AOColor).rgb, 1, ao); + return res; +} + +#endif + +#ifdef _DITHER_ON +float4 Dither_float4(float4 input, float4 screenPos, float normalizedDistance) +{ + static const float DITHER_THRESHOLDS[16] = + { + 0.0, 0.5, 0.125, 0.625, + 0.75, 0.25, 0.875, 0.375, + 0.1875, 0.6875, 0.0625, 0.5625, + 0.9375, 0.4375, 0.8125, 0.3125 + }; + + float2 screenUV = screenPos.xy / screenPos.w; + screenUV = screenUV * 0.5 + 0.5; + + float2 pixelPos = screenUV * _ScreenParams.xy * ACCESS_PROP_FLOAT(_DitherScale); + uint index = (uint(pixelPos.x) & 3) * 4 + (uint(pixelPos.y) & 3); + + float dither = DITHER_THRESHOLDS[index] * normalizedDistance; + + float4 result = input; + result.a = saturate(result.a - dither); + return result; +} +#endif + +float AntiAliasing(float gradient, float cutOff) +{ + cutOff = max(0.01, cutOff); + float gradientCutOff = cutOff - gradient; + + float2 ddxVector = float2(ddx(gradientCutOff), ddy(gradientCutOff)); + + float res = gradientCutOff / length(ddxVector); + + res = saturate(0.5 - res); + + return res; +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl.meta new file mode 100644 index 0000000..8f9e798 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 1d321d03d59fab041814ba51da72831d +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonFunctions.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonStructs.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonStructs.hlsl new file mode 100644 index 0000000..6a98eed --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonStructs.hlsl @@ -0,0 +1,380 @@ +#ifndef ALLIN13DSHADER_COMMON_STRUCTS +#define ALLIN13DSHADER_COMMON_STRUCTS + +#define T_SPACE_PROPERTIES(n1, n2, n3) float3 tspace0 : TEXCOORD##n1; float3 tspace1 : TEXCOORD##n2; float3 tspace2 : TEXCOORD##n3; +#define INIT_T_SPACE(normalWS) \ + o.tspace0 = float3(tangentWS.x, bitangentWS.x, normalWS.x); \ + o.tspace1 = float3(tangentWS.y, bitangentWS.y, normalWS.y); \ + o.tspace2 = float3(tangentWS.z, bitangentWS.z, normalWS.z); + + +#define INIT_DECAL_DATA(decalData) \ + decalData.baseColor = float4(0, 0, 0, 1); \ + decalData.normalTS = float4(0, 0, 0, 0); \ + decalData.emissive = 0; \ + decalData.mask = 0; \ + decalData.unpackedNormal = float3(0, 0, 0); \ + decalData.smoothness = 0; \ + decalData.metallic = 0; \ + decalData.MAOSAlpha = 1; + +#define INIT_EFFECTS_DATA(data) \ + data.mainUV = float2(0, 0); \ + data.rawMainUV = float2(0, 0); \ + data.normalizedScreenSpaceUV = float2(0, 0); \ + data.vertexColor = float4(1, 1, 1, 1); \ + data.vertexColorLuminosity = 1.0; \ + data.vertexOS = float3(0, 0, 0); \ + data.vertexWS = float3(0, 0, 0); \ + data.vertexVS = float3(0, 0, 0); \ + data.normalOS = float3(0, 1, 0); \ + data.normalWS = float3(0, 1, 0); \ + data.viewDirWS = float3(0, 0, -1); \ + data.tangentWS = float3(1, 0, 0); \ + data.bitangentWS = float3(0, 1, 0); \ + data.projPos = float4(0, 0, 0, 0); \ + data.pos = float4(0, 0, 0, 0); \ + data.lightColor = float3(1, 1, 1); \ + data.lightDir = float3(0, -1, 1); \ + data.sceneDepthDiff = 1.0; \ + data.normalizedDepth = 0; \ + data.camDistance = 0; \ + data.camDistanceViewSpace = 0; \ + data.shaderTime = float3(0, 0, 0); \ + data.uv_dist = float2(0, 0); \ + data.uvMatrix = 0; \ + data.uv_matrix_normalMap = 0; \ + data.uv_normalMap = 0; \ + data.uvDiff = 0; \ + data._ShadowCoord = 0; \ + data.metallic = 0; \ + data.smoothness = 1; + +#define INIT_GI(gi) \ + gi.diffuse = float3(0, 0, 0); \ + gi.shadowMask = float4(0, 0, 0, 0); \ + gi.uvLightmap = float2(0, 0); + + +#define UV_FRONT(data) data.uvMatrix._m00_m01 +#define UV_FRONT_WEIGHT(data) data.uvMatrix._m02 + +#define UV_SIDE(data) data.uvMatrix._m10_m11 +#define UV_SIDE_WEIGHT(data) data.uvMatrix._m12 + +#define UV_TOP(data) data.uvMatrix._m20_m21 +#define UV_TOP_WEIGHT(data) data.uvMatrix._m22 + +#define UV_DOWN(data) data.uvMatrix._m30_m31 +#define UV_DOWN_WEIGHT(data) data.uvMatrix._m32 + +#define MAIN_UV(data) data.uvMatrix._m00_m01 + +//Main UV +#define SCALED_MAIN_UV(input) input.mainUV.xy +#define RAW_MAIN_UV(input) input.mainUV.zw + +//Tangent WS +#define TANGENT_WS(input) float3(input.tspace0.x, input.tspace1.x, input.tspace2.x) + +//Interpolator 01 +#define UV_LIGHTMAP(input) input.interpolator_01.xy +#define UV_DIFF(input) input.interpolator_01.zw + +//Interpolator 02 +#define UV_NORMAL_MAP(input) input.interpolator_02.xy +#define UV_EMISSION_MAP(input) input.interpolator_02.zw + +//Interpolator 03 +#define SHADER_TIME(input) input.interpolator_03.xyz +#define FOGCOORD(input) input.interpolator_03.w + +//Interpolator 04 +#define NORMAL_OS(input) input.interpolator_04.xyz +#define VERTEX_COLOR_R(input) input.interpolator_04.w + +//Interpolator 05 +#define POSITION_OS(input) input.interpolator_05.xyz +#define VERTEX_COLOR_G(input) input.interpolator_05.w + +//Interpolator 06 +#define POSITION_WS(input) input.interpolator_06.xyz +#define VERTEX_COLOR_B(input) input.interpolator_06.w + +//Interpolator 07 +#define VIEWDIR_WS(input) input.interpolator_07.xyz +#define VERTEX_COLOR_A(input) input.interpolator_07.w + + +#ifdef _NORMAL_MAP_ON + #define NORMAL_UV_FRONT(data) data.uv_matrix_normalMap._m00_m01 + #define NORMAL_UV_SIDE(data) data.uv_matrix_normalMap._m10_m11 + #define NORMAL_UV_TOP(data) data.uv_matrix_normalMap._m20_m21 + + #define MAIN_NORMAL_UV(data) data.uv_matrix_normalMap._m00_m01 +#endif + + +#ifdef _NORMAL_MAP_ON + #ifdef _TRIPLANAR_MAPPING_ON + #define DISPLACE_ALL_UVS(data, displacementAmount) \ + UV_FRONT(data) += displacementAmount; \ + UV_SIDE(data) += displacementAmount; \ + UV_TOP(data) += displacementAmount; \ + UV_DOWN(data) += displacementAmount; \ + NORMAL_UV_FRONT(data) += displacementAmount; \ + NORMAL_UV_SIDE(data) += displacementAmount; \ + NORMAL_UV_TOP(data) += displacementAmount; \ + data.rawMainUV += displacementAmount; + + #define QUANTIZE_ALL_UVS(data, quantizeFactor) \ + UV_FRONT(data) = floor(UV_FRONT(data) * quantizeFactor) / quantizeFactor; \ + UV_SIDE(data) = floor(UV_SIDE(data) * quantizeFactor) / quantizeFactor; \ + UV_TOP(data) = floor(UV_TOP(data) * quantizeFactor) / quantizeFactor; \ + UV_DOWN(data) = floor(UV_DOWN(data) * quantizeFactor) / quantizeFactor; \ + NORMAL_UV_FRONT(data) = floor(NORMAL_UV_FRONT(data) * quantizeFactor) / quantizeFactor; \ + NORMAL_UV_SIDE(data) = floor(NORMAL_UV_SIDE(data) * quantizeFactor) / quantizeFactor; \ + NORMAL_UV_TOP(data) = floor(NORMAL_UV_TOP(data) * quantizeFactor) / quantizeFactor; \ + data.rawMainUV = floor(data.rawMainUV * quantizeFactor) / quantizeFactor; + + #define FLOOR_ALL_UVS(data) \ + UV_FRONT(data) = floor(UV_FRONT(data)); \ + UV_SIDE(data) = floor(UV_SIDE(data)); \ + UV_TOP(data) = floor(UV_TOP(data)); \ + UV_DOWN(data) = floor(UV_DOWN(data)); \ + NORMAL_UV_FRONT(data) = floor(NORMAL_UV_FRONT(data)); \ + NORMAL_UV_SIDE(data) = floor(NORMAL_UV_SIDE(data)); \ + NORMAL_UV_TOP(data) = floor(NORMAL_UV_TOP(data)); \ + data.rawMainUV = floor(data.rawMainUV); + #else + #define QUANTIZE_ALL_UVS(data, quantizeFactor) \ + MAIN_UV(data) = floor(MAIN_UV(data) * quantizeFactor) / quantizeFactor; \ + MAIN_NORMAL_UV(data) = floor(MAIN_NORMAL_UV(data) * quantizeFactor) / quantizeFactor; \ + data.rawMainUV = floor(data.rawMainUV * quantizeFactor) / quantizeFactor; + + #define DISPLACE_ALL_UVS(data, displacementAmount) \ + MAIN_UV(data) += displacementAmount; \ + MAIN_NORMAL_UV(data) += displacementAmount; \ + data.rawMainUV += displacementAmount; + #endif +#else + #ifdef _TRIPLANAR_MAPPING_ON + #define DISPLACE_ALL_UVS(data, displacementAmount) \ + data.uvMatrix._m00_m01 += displacementAmount; \ + data.uvMatrix._m10_m11 += displacementAmount; \ + data.uvMatrix._m20_m21 += displacementAmount; \ + data.uvMatrix._m30_m31 += displacementAmount; \ + data.rawMainUV += displacementAmount; + + #define QUANTIZE_ALL_UVS(data, quantizeFactor) \ + data.uvMatrix._m00_m01 = floor(data.uvMatrix._m00_m01 * quantizeFactor) / quantizeFactor; \ + data.uvMatrix._m10_m11 = floor(data.uvMatrix._m10_m11 * quantizeFactor) / quantizeFactor; \ + data.uvMatrix._m20_m21 = floor(data.uvMatrix._m20_m21 * quantizeFactor) / quantizeFactor; \ + data.uvMatrix._m30_m31 = floor(data.uvMatrix._m30_m31 * quantizeFactor) / quantizeFactor; \ + data.rawMainUV = floor(data.rawMainUV * quantizeFactor) / quantizeFactor; + #else + #define DISPLACE_ALL_UVS(data, displacementAmount) \ + MAIN_UV(data) += displacementAmount; \ + data.rawMainUV += displacementAmount; + + #define QUANTIZE_ALL_UVS(data, quantizeFactor) \ + MAIN_UV(data) = floor(MAIN_UV(data) * quantizeFactor) / quantizeFactor; \ + data.rawMainUV = floor(data.rawMainUV * quantizeFactor) / quantizeFactor; + #endif +#endif + +#define RECALCULATE_NORMAL_OFFSET 0.01 + +struct AllIn1LightData +{ + float3 lightColor; + float3 lightDir; + float realtimeShadow; + float4 shadowColor; + float distanceAttenuation; + uint layerMask; +}; + +struct AllIn1DecalData +{ + float4 baseColor; + float4 normalTS; + float3 emissive; + float mask; + float3 unpackedNormal; + float smoothness; + float metallic; + float MAOSAlpha; +}; + +struct ShadowCoordStruct +{ + float4 _ShadowCoord : TEXCOORD0; + float4 pos : TEXCOORD1; +}; + +struct FogStruct +{ + float fogCoord : TEXCOORD0; +}; + +struct VertexData +{ + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + float2 uvLightmap : TEXCOORD1; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 vertexColor : COLOR; + + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct FragmentDataOutline +{ + float4 pos : SV_POSITION; + float2 mainUV : TEXCOORD0; + float3 normalWS : TEXCOORD1; + + float4 interpolator_01 : TEXCOORD2; + float4 interpolator_02 : TEXCOORD3; + float4 interpolator_03 : TEXCOORD4; + + float3 positionWS : TEXCOORD5; + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO +}; + +struct FragmentData +{ + float4 pos : SV_POSITION; + float4 mainUV : TEXCOORD0; + + float3 normalWS : TEXCOORD1; + + float4 interpolator_01 : TEXCOORD2; + float4 interpolator_02 : TEXCOORD3; + float4 interpolator_03 : TEXCOORD4; + float4 interpolator_04 : TEXCOORD5; + float4 interpolator_05 : TEXCOORD6; + float4 interpolator_06 : TEXCOORD7; + float4 interpolator_07 : TEXCOORD8; + +#ifdef REQUIRE_TANGENT_WS + T_SPACE_PROPERTIES(9, 10, 11) +#endif + +#if defined(REQUIRE_SCENE_DEPTH) || defined(LOD_FADE_CROSSFADE) + float4 projPos : TEXCOORD12; +#endif + + float4 _ShadowCoord : TEXCOORD13; + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO +}; + +struct FragmentDataShadowCaster +{ + float4 pos : SV_POSITION; + float4 positionOS : TEXCOORD1; + float2 mainUV : TEXCOORD2; + float3 positionWS : TEXCOORD3; + float2 uv2 : TEXCOORD4; + float3 shaderTime : TEXCOORD5; + float3 normalOS : TEXCOORD6; + float3 normalWS : TEXCOORD7; + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO +}; + +struct TriplanarData +{ + float2 uv_triplanar_front; + float2 uv_triplanar_side; + float2 uv_triplanar_top; +}; + +struct AllIn1GI +{ + float3 diffuse; + float4 shadowMask; + float2 uvLightmap; +}; + +// +struct EffectsData +{ + float2 mainUV; + float2 rawMainUV; + + float2 normalizedScreenSpaceUV; + + float4 vertexColor; + float vertexColorLuminosity; + + float3 vertexOS; + float3 vertexWS; + float3 vertexVS; + float3 normalOS; + float3 normalWS; + float3 viewDirWS; + + float3 tangentWS; + float3 bitangentWS; + + float4 projPos; + float4 pos; //Patch to fix the error when UNITY_LIGHT_ATTENUATION is expanded + + float3 lightColor; + float3 lightDir; + + float sceneDepthDiff; + float normalizedDepth; + float camDistance; + float camDistanceViewSpace; + float3 shaderTime; + + float2 uv_dist; + + float4x3 uvMatrix; + float4x3 uv_matrix_normalMap; + float2 uv_normalMap; + + float2 uvDiff; + + float4 _ShadowCoord; + + float metallic; + float smoothness; +}; +// + +#ifdef _TRIPLANAR_MAPPING_ON +float3 GetTriplanarWeights(float3 normal, float2 uv) +{ + float3 weights = abs(normal); + + float transition = 0.0; +#ifdef _TRIPLANAR_NOISE_TRANSITION_ON + float2 scaleUV = ACCESS_PROP_FLOAT4(_TriplanarNoiseTex_ST).xy; + transition = SAMPLE_TEX2D(_TriplanarNoiseTex, uv * scaleUV).r; + transition = (transition - 0.5) * 2.0; + transition *= ACCESS_PROP_FLOAT(_TriplanarTransitionPower); + + normal.xz = lerp(float2(-0.5, -0.5), float2(0.5, 0.5), transition); + + normal = normalize(normal); + weights = abs(normal); +#endif + + weights = pow(weights, ACCESS_PROP_FLOAT(_TriplanarSharpness)); + weights = weights / (weights.x + weights.y + weights.z); + + return weights; +} +#endif + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonStructs.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonStructs.hlsl.meta new file mode 100644 index 0000000..fff369e --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonStructs.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: accf6894604f8af4f8d2f5226925f2cb +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_CommonStructs.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_Features.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_Features.hlsl new file mode 100644 index 0000000..cf20c16 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_Features.hlsl @@ -0,0 +1,226 @@ +#ifndef ALLIN13DSHADER_FEATURES +#define ALLIN13DSHADER_FEATURES + +#if defined(INSTANCING_ON) && !defined(PROCEDURAL_INSTANCING_ON) + #define ALLIN13D_GPU_INSTANCING +#endif + +#if defined(UNITY_DOTS_INSTANCING_ENABLED) || defined(URP_PASS) + #define ALWAYS_DECLARE_PROPERTY +#endif + +#if defined(ALLIN13D_GPU_INSTANCING) + #define BATCHING_BUFFER_START UNITY_INSTANCING_BUFFER_START(UnityPerMaterial) + #define BATCHING_BUFFER_END UNITY_INSTANCING_BUFFER_END(UnityPerMaterial) + +#else + #if defined(URP_PASS) && !defined(PROCEDURAL_INSTANCING_ON) + #define BATCHING_BUFFER_START CBUFFER_START(UnityPerMaterial) + #define BATCHING_BUFFER_END CBUFFER_END + #else + #define BATCHING_BUFFER_START + #define BATCHING_BUFFER_END + #endif +#endif + +//GetMeshRenderingLightLayer +#if defined(URP_PASS) && defined(ALLIN1_LIGHT_LAYERS_SUPPORT) + #define ALLIN1_USE_LIGHT_LAYERS +#endif + +#ifdef URP_PASS + #define DECLARE_TEX2D(texName) \ + TEXTURE2D(texName); \ + SAMPLER(sampler_##texName); + + #define SAMPLE_TEX2D(texName, uv) SAMPLE_TEXTURE2D(texName, sampler_##texName, uv) + #define SAMPLE_TEX2D_DERIVATIVES(texName, uv, ddx, ddy) SAMPLE_TEXTURE2D_GRAD(texName, sampler_##texName, uv, ddx, ddy) + #define SAMPLE_TEX2D_LOD(texName, uv) SAMPLE_TEXTURE2D_LOD(texName, sampler_##texName, uv.xy, 0) + #define SAMPLE_TEX2D_PROJ(texName, uv) SAMPLE_TEXTURE2D(texName, sampler##texName, uv.xy/uv.w) +#else + #define DECLARE_TEX2D(texName) sampler2D texName; + + #define SAMPLE_TEX2D(texName, uv) tex2D(texName, uv) + #define SAMPLE_TEX2D_DERIVATIVES(texName, uv, ddx, ddy) tex2D(texName, uv, ddx, ddy) + #define SAMPLE_TEX2D_LOD(texName, uv) tex2Dlod(texName, uv) + #define SAMPLE_TEX2D_PROJ(texName, uv) tex2Dproj(texName, uv) +#endif + +#define STOCHASTIC_SAMPLING_NO_DEF_DD(texName, uv, stochasticOffset, res) \ + dx = ddx(uv);\ + dy = ddy(uv);\ + res = mul(SAMPLE_TEX2D_DERIVATIVES(texName, uv + hash2D2D(stochasticOffset[0].xy), dx, dy), stochasticOffset[3].x) + \ + mul(SAMPLE_TEX2D_DERIVATIVES(texName, uv + hash2D2D(stochasticOffset[1].xy), dx, dy), stochasticOffset[3].y) + \ + mul(SAMPLE_TEX2D_DERIVATIVES(texName, uv + hash2D2D(stochasticOffset[2].xy), dx, dy), stochasticOffset[3].z); + +#define STOCHASTIC_SAMPLING(texName, uv, stochasticOffset, res) \ + float2 dx = 0;\ + float2 dy = 0;\ + STOCHASTIC_SAMPLING_NO_DEF_DD(texName, uv, stochasticOffset, res) + +#define STOCHASTIC_SAMPLING_COMPLETE_NO_DEF_DD(texName, uv, stochasticOffsetName, res) \ + stochasticOffset = getStochasticOffsets(uv, ACCESS_PROP_FLOAT(_StochasticScale), ACCESS_PROP_FLOAT(_StochasticSkew));\ + STOCHASTIC_SAMPLING_NO_DEF_DD(texName, uv, stochasticOffsetName, res) + +#define STOCHASTIC_SAMPLING_COMPLETE(texName, uv, stochasticOffset, res) \ + stochasticOffset = getStochasticOffsets(uv, ACCESS_PROP_FLOAT(_StochasticScale), ACCESS_PROP_FLOAT(_StochasticSkew));\ + STOCHASTIC_SAMPLING(texName, uv, stochasticOffsetName, res) + + +#if defined(PROCEDURAL_INSTANCING_ON) + #define DECLARE_PROPERTY_FLOAT(name) float name; + #define DECLARE_PROPERTY_FLOAT2(name) float2 name; + #define DECLARE_PROPERTY_FLOAT3(name) float3 name; + #define DECLARE_PROPERTY_FLOAT4(name) float4 name; +#else + #if (defined(INSTANCING_ON) || defined(PROCEDURAL_INSTANCING_ON)) && !defined(URP_PASS) + #define DECLARE_PROPERTY_FLOAT(name) UNITY_DEFINE_INSTANCED_PROP(float, name) + #define DECLARE_PROPERTY_FLOAT2(name) UNITY_DEFINE_INSTANCED_PROP(float2, name) + #define DECLARE_PROPERTY_FLOAT3(name) UNITY_DEFINE_INSTANCED_PROP(float3, name) + #define DECLARE_PROPERTY_FLOAT4(name) UNITY_DEFINE_INSTANCED_PROP(float4, name) + #else + #define DECLARE_PROPERTY_FLOAT(name) float name; + #define DECLARE_PROPERTY_FLOAT2(name) float2 name; + #define DECLARE_PROPERTY_FLOAT3(name) float3 name; + #define DECLARE_PROPERTY_FLOAT4(name) float4 name; + #endif +#endif + + +//------ Shader features -------- +#pragma shader_feature_local_fragment _ALLIN13D_SURFACE_TRANSPARENT +#if !defined(ALLIN1_SHADER_VARIANT) + #include_with_pragmas "../ShaderLibrary/AllIn13DShader_ShaderFeatures.hlsl" +#endif +//------------------------------ + +#if defined(_SPECULARMODEL_CLASSIC) || defined(_SPECULARMODEL_TOON) || defined(_SPECULARMODEL_ANISOTROPIC) || defined(_SPECULARMODEL_ANISOTROPICTOON) + #define SPECULAR_ON +#else + #if !defined(_SPECULARMODEL_NONE) + #define _SPECULARMODEL_NONE + #endif +#endif + +#if defined(_LIGHTMODEL_CLASSIC) || defined(_LIGHTMODEL_TOON) || defined(_LIGHTMODEL_TOONRAMP) || defined(_LIGHTMODEL_HALFLAMBERT) || defined(_LIGHTMODEL_FAKEGI) || defined(_LIGHTMODEL_FASTLIGHTING) + #define LIGHT_ON +#else + #if !defined(_LIGHTMODEL_NONE) + #define _LIGHTMODEL_NONE + #endif +#endif + +#if (!defined(FORWARD_ADD_PASS) && defined(BIRP_PASS)) || defined(URP_PASS) + #define ADDITIONAL_LIGHT_LOOP +#endif + +#if defined(URP_PASS) + #if defined(ALLIN1_FOG_SUPPORT) && defined(_FOG_ON) + #define FOG_ENABLED + #endif +#elif defined(BIRP_PASS) + #if defined(_FOG_ON) + #define FOG_ENABLED + #endif +#endif + +//#pragma shader_feature_local _REFLECTIONS_NONE _REFLECTIONS_CLASSIC _REFLECTIONS_TOON + +#if defined(_REFLECTIONS_CLASSIC) || defined(_REFLECTIONS_TOON) + #define REFLECTIONS_ON +#else + #if !defined(_REFLECTIONS_NONE) + #define _REFLECTIONS_NONE + #endif +#endif + +#if !defined(_OUTLINETYPE_NONE) + #define OUTLINE_ON +#endif + +#if defined(_INTERSECTION_GLOW_ON) || defined(_SCREEN_SPACE_UV_ON) || defined(_INTERSECTION_FADE_ON) || defined(_DEPTH_COLORING_ON) || defined(_DITHER_ON) + #define REQUIRE_SCENE_DEPTH +#endif + +#if defined(REQUIRE_SCENE_DEPTH) || defined(LOD_FADE_CROSSFADE) + #define REQUIRE_SCREEN_POS +#endif + +#if defined(_SCREEN_SPACE_UV_ON) || defined(REQUIRE_SCENE_DEPTH) || defined(_FADE_BY_CAM_DISTANCE_ON) + #define REQUIRE_CAM_DISTANCE +#endif + +#if defined(_SPECULARMODEL_ANISOTROPIC) || defined(_SPECULARMODEL_ANISOTROPICTOON) || defined(_NORMAL_MAP_ON) + #define REQUIRE_TANGENT_WS +#endif + +#if defined(URP_PASS) + #if defined(LIGHTMAP_ON) && defined(LIGHTMAP_SHADOW_MIXING) + #define SUBTRACTIVE_LIGHTING + #endif +#else + #if defined(LIGHTMAP_ON) && defined(SHADOWS_SCREEN) && defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) + #define SUBTRACTIVE_LIGHTING + #endif +#endif + +//Dependencies +#if !defined(LIGHT_ON) + #undef REFLECTIONS_ON + #undef _NORMAL_MAP_ON + #undef SPECULAR_ON +#endif + +#include "../ShaderLibrary/AllIn13DShader_GlobalPropertiesAndTexturesDeclaration.hlsl" + + +//-------- Properties Buffer ----------- + +BATCHING_BUFFER_START + #include "../ShaderLibrary/AllIn13DShader_BufferPropertiesDeclaration.hlsl" +BATCHING_BUFFER_END + + +#ifdef UNITY_DOTS_INSTANCING_ENABLED + #undef DECLARE_PROPERTY_FLOAT + #undef DECLARE_PROPERTY_FLOAT2 + #undef DECLARE_PROPERTY_FLOAT3 + #undef DECLARE_PROPERTY_FLOAT4 + #undef ALLIN13DSHADER_BUFFERPROPERTIESDECLARATION + + #define DECLARE_PROPERTY_FLOAT(name) UNITY_DOTS_INSTANCED_PROP_OVERRIDE_SUPPORTED(float, name) + #define DECLARE_PROPERTY_FLOAT2(name) UNITY_DOTS_INSTANCED_PROP_OVERRIDE_SUPPORTED(float2, name) + #define DECLARE_PROPERTY_FLOAT3(name) UNITY_DOTS_INSTANCED_PROP_OVERRIDE_SUPPORTED(float3, name) + #define DECLARE_PROPERTY_FLOAT4(name) UNITY_DOTS_INSTANCED_PROP_OVERRIDE_SUPPORTED(float4, name) + + UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata) + #include "../ShaderLibrary/AllIn13DShader_BufferPropertiesDeclaration.hlsl" + UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata) +#endif + +//---------------------------------- + +#if defined(UNITY_DOTS_INSTANCING_ENABLED) + #define ACCESS_PROP_FLOAT(name) UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float, name) + #define ACCESS_PROP_FLOAT2(name) UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float2, name) + #define ACCESS_PROP_FLOAT3(name) UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float3, name) + #define ACCESS_PROP_FLOAT4(name) UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, name) + #define ACCESS_PROP_TILING_AND_OFFSET(name) UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_CUSTOM_DEFAULT(float4, name, float4(1, 1, 0, 0)) + +#elif defined(ALLIN13D_GPU_INSTANCING) + #define ACCESS_PROP_FLOAT(name) UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, name) + #define ACCESS_PROP_FLOAT2(name) UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, name) + #define ACCESS_PROP_FLOAT3(name) UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, name) + #define ACCESS_PROP_FLOAT4(name) UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, name) + #define ACCESS_PROP_TILING_AND_OFFSET(name) UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, name) + +#else + #define ACCESS_PROP_FLOAT(name) name + #define ACCESS_PROP_FLOAT2(name) name + #define ACCESS_PROP_FLOAT3(name) name + #define ACCESS_PROP_FLOAT4(name) name + #define ACCESS_PROP_TILING_AND_OFFSET(name) name + +#endif + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_Features.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_Features.hlsl.meta new file mode 100644 index 0000000..4ac857f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_Features.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 27dc0b905bafffe47966f6ec1e846e00 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_Features.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl new file mode 100644 index 0000000..e6f9525 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl @@ -0,0 +1,145 @@ +#ifndef ALLIN13DSHADER_FEATURESURP +#define ALLIN13DSHADER_FEATURESURP + +#ifdef ALLIN1_DOTS_INSTANCING_SUPPORT + #pragma target 4.5 +#else + #pragma target 3.0 +#endif + + +#if defined(ALLIN1_FORWARD_PASS) + #ifdef ALLIN1_GPU_INSTANCING_SUPPORT + #pragma multi_compile_instancing + #endif + + #ifdef ALLIN1_DOTS_INSTANCING_SUPPORT + #pragma multi_compile _ DOTS_INSTANCING_ON + #endif + + #ifdef ALLIN1_FOG_SUPPORT + #if UNITY_VERSION >= 60020000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Fog.hlsl" + #else + #pragma multi_compile_fog + #endif + #endif + + #ifdef ALLIN1_CAST_SHADOWS_SUPPORT + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + #pragma multi_compile _ _SHADOWS_SOFT + #endif + + #ifdef ALLIN1_SSO_SUPPORT + #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION + #endif + + #ifdef ALLIN1_ADDITIONAL_LIGHTS_SUPPORT + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + #endif + + #ifdef ALLIN1_REFLECTIONS_PROBES_SUPPORT_UNITY6 + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + #pragma multi_compile_fragment _ _REFLECTION_PROBE_ATLAS + #endif + + #ifdef ALLIN1_ADAPTATIVE_PROBE_VOLUMES_UNITY6 + #if UNITY_VERSION >= 60000000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl" + #endif + #endif + + #ifdef ALLIN1_LIGHT_LAYERS_SUPPORT + #pragma multi_compile _ _LIGHT_LAYERS + #endif + + #ifdef ALLIN1_SHADOW_MASK_SUPPORT + #pragma multi_compile _ SHADOWS_SHADOWMASK // v10+ only + #endif + + #ifdef ALLIN1_FORWARD_PLUS_SUPPORT_UNITY6 + #if UNITY_VERSION >= 60020000 + #define ALLIN1_USE_FORWARD_PLUS USE_CLUSTER_LIGHT_LOOP + #define ALLIN1_FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK CLUSTER_LIGHT_LOOP_SUBTRACTIVE_LIGHT_CHECK + + #pragma multi_compile _ _CLUSTER_LIGHT_LOOP + #else + #define ALLIN1_USE_FORWARD_PLUS USE_FORWARD_PLUS + #define ALLIN1_FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK + + #pragma multi_compile _ _FORWARD_PLUS + #endif + #endif + + #ifdef ALLIN1_LIGHTMAPS_SUPPORT + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING // v10+ only, renamed from "_MIXED_LIGHTING_SUBTRACTIVE" + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #endif + + #ifdef ALLIN1_LIGHT_COOKIES_SUPPORT + #pragma multi_compile_fragment _ _LIGHT_COOKIES + #endif + + #ifdef ALLIN1_DECALS_SUPPORT + #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 + #endif + + #ifdef ALLIN1_LODCROSSFADE_SUPPORT + #pragma multi_compile _ LOD_FADE_CROSSFADE + #endif + +#elif defined(SHADOW_CASTER_PASS) + #pragma multi_compile_fwdadd_fullshadows + + #ifdef ALLIN1_GPU_INSTANCING_SUPPORT + #pragma multi_compile_instancing + #endif + + #ifdef ALLIN1_DOTS_INSTANCING_SUPPORT + #pragma multi_compile _ DOTS_INSTANCING_ON + #endif + + #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW + +#elif defined(ALLIN1_DEPTH_ONLY_PASS) + #ifdef ALLIN1_GPU_INSTANCING_SUPPORT + #pragma multi_compile_instancing + #endif + + #ifdef ALLIN1_DOTS_INSTANCING_SUPPORT + #pragma multi_compile _ DOTS_INSTANCING_ON + #endif + +#elif defined(ALLIN1_DEPTH_NORMALS_PASS) + #ifdef ALLIN1_GPU_INSTANCING_SUPPORT + #pragma multi_compile_instancing + #endif + + #ifdef ALLIN1_DOTS_INSTANCING_SUPPORT + #pragma multi_compile _ DOTS_INSTANCING_ON + #endif + +#elif defined(ALLIN1_OUTLINE_PASS) + #ifdef ALLIN1_GPU_INSTANCING_SUPPORT + #pragma multi_compile_instancing + #endif + + #ifdef ALLIN1_DOTS_INSTANCING_SUPPORT + #pragma multi_compile _ DOTS_INSTANCING_ON + #endif + + #ifdef ALLIN1_FOG_SUPPORT + #if UNITY_VERSION >= 60020000 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Fog.hlsl" + #else + #pragma multi_compile_fog + #endif + #endif + +#endif + + +#endif //ALLIN13DSHADER_FEATURESURP \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl.meta new file mode 100644 index 0000000..463eb06 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: eabe5d205fb5e244c9e9a4db44ae53f6 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl new file mode 100644 index 0000000..c52c504 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl @@ -0,0 +1,15 @@ +#ifndef ALLIN13DSHADER_FEATURESURP_DEFINES +#define ALLIN13DSHADER_FEATURESURP_DEFINES + +#define ALLIN1_GPU_INSTANCING_SUPPORT +#define ALLIN1_FOG_SUPPORT +#define ALLIN1_LIGHTMAPS_SUPPORT +#define ALLIN1_ADDITIONAL_LIGHTS_SUPPORT +#define ALLIN1_CAST_SHADOWS_SUPPORT +#define ALLIN1_SHADOW_MASK_SUPPORT +#define ALLIN1_FORWARD_PLUS_SUPPORT_UNITY6 +#define ALLIN1_ADAPTATIVE_PROBE_VOLUMES_UNITY6 +#define ALLIN1_SSO_SUPPORT + + +#endif //ALLIN13DSHADER_FEATURESURP_DEFINES \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl.meta new file mode 100644 index 0000000..0586afe --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: dbe4d28eefee6bc44a32ba4795821c1a +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FeaturesURP_Defines.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl new file mode 100644 index 0000000..2073bca --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl @@ -0,0 +1,411 @@ +#ifndef ALLIN13DSHADER_FRAGMENT_EFFECTS +#define ALLIN13DSHADER_FRAGMENT_EFFECTS + +// +float3 HueShift(float3 inputColor, float hueShift, float hueSaturation, float hueBrightness) +{ + float3 res = inputColor; + + float cosHsv = hueBrightness * hueSaturation * cos(hueShift * 3.14159265 / 180); + float sinHsv = hueBrightness * hueSaturation * sin(hueShift * 3.14159265 / 180); + res.r = (.299 * hueBrightness + .701 * cosHsv + .168 * sinHsv) * inputColor.x + + (.587 * hueBrightness - .587 * cosHsv + .330 * sinHsv) * inputColor.y + + (.114 * hueBrightness - .114 * cosHsv - .497 * sinHsv) * inputColor.z; + res.g = (.299 * hueBrightness - .299 * cosHsv - .328 * sinHsv) *inputColor.x + + (.587 * hueBrightness + .413 * cosHsv + .035 * sinHsv) * inputColor.y + + (.114 * hueBrightness - .114 * cosHsv + .292 * sinHsv) * inputColor.z; + res.b = (.299 * hueBrightness - .3 * cosHsv + 1.25 * sinHsv) * inputColor.x + + (.587 * hueBrightness - .588 * cosHsv - 1.05 * sinHsv) * inputColor.y + + (.114 * hueBrightness + .886 * cosHsv - .203 * sinHsv) * inputColor.z; + + return res; +} + +float3 ContrastBrightness(float3 inputColor, float contrast, float brightness) +{ + float3 res = max(0, (inputColor - float3(0.5, 0.5, 0.5)) * contrast + float3(0.5, 0.5, 0.5) + brightness); + return res; +} + + +#if defined(_AFFECTED_BY_LIGHTMAPS_ON) && defined(_LIGHTMAP_COLOR_CORRECTION_ON) +float3 LightmapColorCorrection(float3 lightmap) +{ + float3 res = lightmap; + + res = HueShift(res, ACCESS_PROP_FLOAT(_HueShiftLM), ACCESS_PROP_FLOAT(_HueSaturationLM), ACCESS_PROP_FLOAT(_HueBrightnessLM)); + res = ContrastBrightness(res, ACCESS_PROP_FLOAT(_ContrastLM), ACCESS_PROP_FLOAT(_BrightnessLM)); + + return res; +} +#endif +// + +#ifdef _HUE_SHIFT_ON +float3 HueShift(float3 inputColor) +{ + float3 res = HueShift(inputColor, ACCESS_PROP_FLOAT(_HueShift), ACCESS_PROP_FLOAT(_HueSaturation), ACCESS_PROP_FLOAT(_HueBrightness)); + return res; +} +#endif + + +#ifdef _ALBEDO_VERTEX_COLOR_ON +float4 AlbedoVertexColor(float4 inputColor, EffectsData data) +{ + float4 res = inputColor; + +#ifdef _ALBEDOVERTEXCOLORMODE_MULTIPLY + float3 multipliedColor = res.rgb * data.vertexColor.rgb; + res.rgb = lerp(res.rgb, multipliedColor, ACCESS_PROP_FLOAT(_VertexColorBlending)); +#else + res.rgb = lerp(inputColor.rgb, data.vertexColor.rgb, ACCESS_PROP_FLOAT(_VertexColorBlending)); +#endif + + return res; +} +#endif + +#if defined(_TEXTURE_BLENDING_ON) +float4 TextureBlending(float4 inputColor, EffectsData data) +{ + float4 res = inputColor; + + #if defined(_TEXTUREBLENDINGSOURCE_TEXTURE) + float2 blendingMaskUV = SIMPLE_CUSTOM_TRANSFORM_TEX(data.rawMainUV, _TexBlendingMask); + float3 maskColor = SAMPLE_TEX2D(_TexBlendingMask, blendingMaskUV).rgb; + #if defined(_TEXTUREBLENDINGMODE_RGB) + float maskG = smoothstep(ACCESS_PROP_FLOAT(_BlendingMaskCutoffG), ACCESS_PROP_FLOAT(_BlendingMaskCutoffG) + ACCESS_PROP_FLOAT(_BlendingMaskSmoothnessG), maskColor.g); + float maskB = smoothstep(ACCESS_PROP_FLOAT(_BlendingMaskCutoffB), ACCESS_PROP_FLOAT(_BlendingMaskCutoffB) + ACCESS_PROP_FLOAT(_BlendingMaskSmoothnessB), maskColor.b); + maskColor = float3(1.0, maskG, maskB); + #else + float maskBlackAndWhite = smoothstep(ACCESS_PROP_FLOAT(_BlendingMaskCutoffWhite), ACCESS_PROP_FLOAT(_BlendingMaskCutoffWhite) + ACCESS_PROP_FLOAT(_BlendingMaskSmoothnessWhite), maskColor.r); + maskColor = float3(maskBlackAndWhite, maskBlackAndWhite, maskBlackAndWhite); + #endif + #else + float3 maskColor = data.vertexColor.rgb; + float maskG = smoothstep(ACCESS_PROP_FLOAT(_BlendingMaskCutoffG), ACCESS_PROP_FLOAT(_BlendingMaskCutoffG) + ACCESS_PROP_FLOAT(_BlendingMaskSmoothnessG), maskColor.g); + float maskB = smoothstep(ACCESS_PROP_FLOAT(_BlendingMaskCutoffB), ACCESS_PROP_FLOAT(_BlendingMaskCutoffB) + ACCESS_PROP_FLOAT(_BlendingMaskSmoothnessB), maskColor.b); + + maskColor.g = maskG; + maskColor.b = maskB; + #endif + + #ifdef _STOCHASTIC_SAMPLING_ON + float2 dx = 0; + float2 dy = 0; + + float stochasticScale = ACCESS_PROP_FLOAT(_StochasticScale); + float stochasticSkew = ACCESS_PROP_FLOAT(_StochasticSkew); + #endif + + #ifdef _TEXTUREBLENDINGMODE_RGB + float2 texGUV = SIMPLE_CUSTOM_TRANSFORM_TEX(data.rawMainUV, _BlendingTextureG); + float2 texBUV = SIMPLE_CUSTOM_TRANSFORM_TEX(data.rawMainUV, _BlendingTextureB); + + float4 texG = 0; + float4 texB = 0; + #ifdef _STOCHASTIC_SAMPLING_ON + float4x3 stochasticOffsets_G = getStochasticOffsets(texGUV, stochasticScale, stochasticSkew); + STOCHASTIC_SAMPLING_NO_DEF_DD(_BlendingTextureG, texGUV, stochasticOffsets_G, texG) + + float4x3 stochasticOffsets_B = getStochasticOffsets(texBUV, stochasticScale, stochasticSkew); + STOCHASTIC_SAMPLING_NO_DEF_DD(_BlendingTextureB, texGUV, stochasticOffsets_B, texB) + #else + texG = SAMPLE_TEX2D(_BlendingTextureG, texGUV); + texB = SAMPLE_TEX2D(_BlendingTextureB, texBUV); + #endif + + res = lerp(res, texG, maskColor.g); + res = lerp(res, texB, maskColor.b); + #else + float2 texWhiteUV = SIMPLE_CUSTOM_TRANSFORM_TEX(data.rawMainUV, _BlendingTextureWhite); + + float4 texWhite = 0; + #ifdef _STOCHASTIC_SAMPLING_ON + float4x3 stochasticOffsets_W = getStochasticOffsets(texWhiteUV, stochasticScale, stochasticSkew); + STOCHASTIC_SAMPLING_NO_DEF_DD(_BlendingTextureWhite, texWhiteUV, stochasticOffsets_W, texWhite) + #else + texWhite = SAMPLE_TEX2D(_BlendingTextureWhite, texWhiteUV); + #endif + + res = lerp(res, texWhite, maskColor.r); + #endif + + return res; +} +#endif + + +#ifdef _HOLOGRAM_ON +float4 Hologram(float4 inputColor, EffectsData data) +{ + float4 res = inputColor; + + float3 dir = normalize(ACCESS_PROP_FLOAT3(_HologramLineDirection).xyz); + + // Calculate primary hologram pattern using direction projection + float3 scrollPos1 = data.vertexWS * ACCESS_PROP_FLOAT(_HologramFrequency) + (data.shaderTime.y * ACCESS_PROP_FLOAT(_HologramScrollSpeed)); + float3 scrollUV1 = frac(scrollPos1); + + float projectedValue1 = dot(scrollUV1, normalize(dir)); + float distance1 = abs(projectedValue1 - ACCESS_PROP_FLOAT(_HologramLineCenter)) * ACCESS_PROP_FLOAT(_HologramLineSpacing); + float gradientMask1 = 1 - distance1; + gradientMask1 = pow(saturate(gradientMask1), ACCESS_PROP_FLOAT(_HologramLineSmoothness)); + gradientMask1 = max(gradientMask1, ACCESS_PROP_FLOAT(_HologramBaseAlpha)); + + // Calculate accent line pattern using direction projection + float3 scrollPos2 = data.vertexWS * ACCESS_PROP_FLOAT(_HologramAccentFrequency) + (data.shaderTime.y * ACCESS_PROP_FLOAT(_HologramAccentSpeed)); + float3 scrollUV2 = frac(scrollPos2); + + float projectedValue2 = dot(scrollUV2, normalize(dir)); + float distance2 = abs(projectedValue2 - ACCESS_PROP_FLOAT(_HologramLineCenter)) * ACCESS_PROP_FLOAT(_HologramLineSpacing); + float gradientMask2 = 1 - distance2; + gradientMask2 = pow(saturate(gradientMask2), ACCESS_PROP_FLOAT(_HologramLineSmoothness)); + + // Combine both patterns + float combinedMask = saturate(gradientMask1 * ACCESS_PROP_FLOAT(_HologramAlpha) + gradientMask2 * ACCESS_PROP_FLOAT(_HologramAccentAlpha)); + + float4 finalColor = ACCESS_PROP_FLOAT4(_HologramColor); + finalColor.a = combinedMask * ACCESS_PROP_FLOAT4(_HologramColor).a; + + res *= finalColor; + + return res; +} +#endif + +#ifdef _MATCAP_ON + +float3 Matcap(EffectsData data) +{ +#ifdef _NORMAL_MAP_ON + float3 normalMapOS = normalize(mul(UNITY_MATRIX_IT_MV, float4(data.normalWS, 0.0)).xyz); + float3 normalVS = normalize(mul(UNITY_MATRIX_MV, float4(normalMapOS, 0.0)).xyz); +#else + float3 normalVS = normalize(mul(UNITY_MATRIX_MV, float4(data.normalOS, 0.0)).xyz); +#endif + + float3 positionVSDir = normalize(GetPositionVS(data.vertexOS)); + + float3 normalCrossPosition = cross(positionVSDir, normalVS); + + float u = (-normalCrossPosition.y * 0.5) + 0.5; + float v = (normalCrossPosition.x * 0.5) + 0.5; + + float2 matcapUV = float2(u, v); + float3 res = SAMPLE_TEX2D(_MatcapTex, matcapUV).rgb * ACCESS_PROP_FLOAT(_MatcapIntensity); + return res; +} +#endif + + +#ifdef _COLOR_RAMP_ON +float4 ColorRamp(float4 inputColor, EffectsData data) +{ + float luminance = GetLuminance(inputColor); + luminance = saturate(luminance + ACCESS_PROP_FLOAT(_ColorRampLuminosity)); + + float2 rampUV = float2(luminance, 0); + rampUV.x *= ACCESS_PROP_FLOAT(_ColorRampTiling); + rampUV.x += frac(data.shaderTime.x * ACCESS_PROP_FLOAT(_ColorRampScrollSpeed)); + + float3 colorRamp = SAMPLE_TEX2D(_ColorRampTex, rampUV).rgb; + float3 resRGB = lerp(inputColor.rgb, colorRamp, ACCESS_PROP_FLOAT(_ColorRampBlend)); + + float4 res = float4(resRGB, inputColor.a); + + return res; +} +#endif + +#ifdef _HIT_ON + +float4 Hit(float4 inputColor) +{ + float3 resRGB = lerp(inputColor.rgb, ACCESS_PROP_FLOAT4(_HitColor).rgb * ACCESS_PROP_FLOAT(_HitGlow), ACCESS_PROP_FLOAT(_HitBlend)); + float4 res = float4(resRGB, inputColor.a); + return res; +} + +#endif +#ifdef _RIM_LIGHTING_ON +float3 Rim(float3 inputColorRGB, EffectsData data) +{ + float3 rimOffset = ACCESS_PROP_FLOAT3(_RimOffset); + float rimIntensity = 0; + + UNITY_BRANCH + if(dot(rimOffset, rimOffset) > 0.001f) //If we have an offset we calculate it + { + float3 viewSpaceOffset = mul((float3x3)UNITY_MATRIX_V, -rimOffset); + float3 normalizedViewDir = normalize(data.viewDirWS); + float3 biasedViewDir = normalize(normalizedViewDir + viewSpaceOffset); + float NdotV = saturate(dot(data.normalWS, biasedViewDir)); + rimIntensity = smoothstep(ACCESS_PROP_FLOAT(_MinRim), ACCESS_PROP_FLOAT(_MaxRim), 1 - NdotV) * ACCESS_PROP_FLOAT(_RimAttenuation); + } + else //Otherwise we take quick path + { + float3 normalizedViewDir = normalize(data.viewDirWS); + float NdotV = saturate(dot(data.normalWS, normalizedViewDir)); + rimIntensity = smoothstep(ACCESS_PROP_FLOAT(_MinRim), ACCESS_PROP_FLOAT(_MaxRim), 1 - NdotV) * ACCESS_PROP_FLOAT(_RimAttenuation); + } + + return lerp(inputColorRGB, ACCESS_PROP_FLOAT4(_RimColor).rgb, rimIntensity); +} +#endif + +#ifdef _GREYSCALE_ON +float3 Greyscale(float3 inputColorRGB) +{ + float3 res = inputColorRGB; + float luminance = GetLuminance(res); + luminance = saturate(luminance + ACCESS_PROP_FLOAT(_GreyscaleLuminosity)); + res = lerp(res, luminance * ACCESS_PROP_FLOAT4(_GreyscaleTintColor).rgb, ACCESS_PROP_FLOAT(_GreyscaleBlending)); + + return res; +} +#endif + +#ifdef _POSTERIZE_ON +float3 Posterize(float3 inputColorRGB) +{ + float3 res = inputColorRGB; + float gamma = ACCESS_PROP_FLOAT(_PosterizeGamma); + float numColors = ACCESS_PROP_FLOAT(_PosterizeNumColors); + res.rgb = pow(res.rgb, gamma) * numColors; + res.rgb = floor(res.rgb) / numColors; + res.rgb = pow(res.rgb, 1.0 / gamma); + + return res; +} +#endif + +#ifdef _HIGHLIGHTS_ON +float3 Highlights(float3 inputColorRGB, EffectsData data) +{ + float3 normalizedLightDir = normalize(data.lightDir); + float3 offsetLightDir = normalize(normalizedLightDir + ACCESS_PROP_FLOAT3(_HighlightOffset)); + float3 normalizedViewDir = normalize(data.viewDirWS); + + float NdotL = saturate(dot(data.normalWS, offsetLightDir)); + float NdotV = saturate(dot(data.normalWS, normalizedViewDir)); + float rimFactor = 1.0 - NdotV; + + float highlightCutoff = ACCESS_PROP_FLOAT(_HighlightCutoff); + float highlightSmoothness = ACCESS_PROP_FLOAT(_HighlightSmoothness); + float highlightsIntensity = smoothstep(highlightCutoff, highlightCutoff + highlightSmoothness, rimFactor); + + float3 highlights = highlightsIntensity * NdotL * ACCESS_PROP_FLOAT4(_HighlightsColor).rgb * ACCESS_PROP_FLOAT(_HighlightsStrength); + + return inputColorRGB * (highlights + 1); +} +#endif + +#ifdef _CONTRAST_BRIGHTNESS_ON +float3 ContrastBrightness(float3 inputColorRGB) +{ + float3 res = ContrastBrightness(inputColorRGB, ACCESS_PROP_FLOAT(_Contrast), ACCESS_PROP_FLOAT(_Brightness)); + return res; +} +#endif + +#ifdef _HEIGHT_GRADIENT_ON +float4 HeightGradient(float4 inputColor, EffectsData data) +{ + float4 res = inputColor; + + + #ifdef _HEIGHTGRADIENTPOSITIONSPACE_WORLD + float3 selectedPos = data.vertexWS; + #else + float3 selectedPos = data.vertexOS; + #endif + + float gradient = RemapFloat(selectedPos.y, ACCESS_PROP_FLOAT(_MinGradientHeight), ACCESS_PROP_FLOAT(_MaxGradientHeight), 0.0, 1.0); + gradient = saturate(gradient); + + float4 gradientColor = lerp(ACCESS_PROP_FLOAT4(_GradientHeightColor01), ACCESS_PROP_FLOAT4(_GradientHeightColor02), gradient); + + res *= gradientColor; + + return res; +} +#endif + +#ifdef _INTERSECTION_GLOW_ON +float4 IntersectionGlow(float4 inputColor, EffectsData data) +{ + float4 res = inputColor; + + float depthGlowMask = saturate(ACCESS_PROP_FLOAT(_DepthGlowDist) * pow(max(0, 1 - data.sceneDepthDiff), ACCESS_PROP_FLOAT(_DepthGlowPower))); + + res.rgb = lerp(res.rgb, ACCESS_PROP_FLOAT(_DepthGlowGlobalIntensity) * res.rgb, depthGlowMask); + res.rgb += ACCESS_PROP_FLOAT4(_DepthGlowColor).rgb * ACCESS_PROP_FLOAT(_DepthGlowColorIntensity) * depthGlowMask * res.a; + + return res; +} +#endif + +#ifdef _DEPTH_COLORING_ON + +float4 DepthColoring(float4 inputColor, EffectsData data) +{ + float4 res = inputColor; + + float eyeDepth = GetEyeDepth(data.vertexVS); + float eyeDepth01 = smoothstep(global_MinDepth, global_MinDepth + global_DepthZoneLength, eyeDepth); + eyeDepth01 = pow(eyeDepth01, global_DepthGradientFallOff); + +#ifdef FORWARD_ADD_PASS + res *= (1 - eyeDepth01); +#else + float4 depthCol = SAMPLE_TEX2D(global_DepthGradient, float2(eyeDepth01, 0)); + res = lerp(res, depthCol, depthCol.a); +#endif + + + + return res; +} + +#endif + +#ifdef _SUBSURFACE_SCATTERING_ON +float4 SubsurfaceScattering(float4 inputColor, EffectsData data) +{ + float4 res = inputColor; + + float4 sssMapColor = SAMPLE_TEX2D(_SSSMap, data.mainUV); + + //Why do we need to add 1000 for this to look good? + float3 lightColor = GetMainLightColorRGB() * 5; + float lightIntensity = GetMainLightIntensity(); + + float3 normalizedViewDir = normalize(data.viewDirWS); + float3 scatterNormal = (data.normalWS * ACCESS_PROP_FLOAT(_NormalInfluence)) + data.lightDir; + scatterNormal = -normalize(scatterNormal); + + float VdotScatterNormal = saturate(dot(scatterNormal, normalizedViewDir)); + + float sssPower = max(1.0, ACCESS_PROP_FLOAT(_SSSPower)); + float backScatterFactor = pow(VdotScatterNormal, sssPower); + + float frontScatter = saturate(dot(data.normalWS, data.lightDir)); // How directly light hits surface + float frontVdotN = 1.0 - saturate(dot(normalizedViewDir, data.normalWS)); // Fresnel-like front falloff + frontVdotN = pow(frontVdotN, ACCESS_PROP_FLOAT(_SSSFrontPower)); + float frontScatterFactor = frontScatter * frontVdotN * ACCESS_PROP_FLOAT(_SSSFrontAtten); + + float scatterIntensity = max(backScatterFactor, frontScatterFactor) * ACCESS_PROP_FLOAT(_SSSAtten) * sssMapColor.r; + + // Simulate wavelength-dependent scattering with original scatter calculation + float3 deepScatterColor = float3(1.0, 0.3, 0.2); + float3 scatterColor = scatterIntensity * lightColor.rgb * lightIntensity * ACCESS_PROP_FLOAT4(_SSSColor).rgb; + scatterColor *= lerp(float3(1,1,1), deepScatterColor, VdotScatterNormal); + + res.rgb += scatterColor * inputColor.rgb; + return res; +} +#endif + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl.meta new file mode 100644 index 0000000..893df77 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 2a5af0d8118cd0d4d8efc233725d9bc2 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_FragmentEffects.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_GlobalPropertiesAndTexturesDeclaration.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_GlobalPropertiesAndTexturesDeclaration.hlsl new file mode 100644 index 0000000..5ad0017 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_GlobalPropertiesAndTexturesDeclaration.hlsl @@ -0,0 +1,119 @@ +#ifndef ALLIN13DSHADER_GLOBALPROPERTIESANDTEXTURESDECLARATION +#define ALLIN13DSHADER_GLOBALPROPERTIESANDTEXTURESDECLARATION + +DECLARE_TEX2D(_MainTex) + +#if defined(_TEXTURE_BLENDING_ON) + #if defined(_TEXTUREBLENDINGMODE_RGB) + DECLARE_TEX2D(_BlendingTextureG) + DECLARE_TEX2D(_BlendingTextureB) + #else + DECLARE_TEX2D(_BlendingTextureWhite) + #endif + + #if defined(_TEXTUREBLENDINGSOURCE_TEXTURE) + DECLARE_TEX2D(_TexBlendingMask) + #endif + + #if defined(_NORMAL_MAP_ON) + #if defined(_TEXTUREBLENDINGMODE_RGB) + DECLARE_TEX2D(_BlendingNormalMapG) + DECLARE_TEX2D(_BlendingNormalMapB) + #else + DECLARE_TEX2D(_BlendingNormalMapWhite) + #endif + #endif +#endif + +#if defined(REQUIRE_TANGENT_WS) + DECLARE_TEX2D(_NormalMap) +#endif + +#if defined(_COLOR_RAMP_ON) + DECLARE_TEX2D(_ColorRampTex) +#endif + +// ----- Global Properties +float global_MinDepth; +float global_DepthZoneLength; +float global_DepthGradientFallOff; + +#if defined(REQUIRE_SCENE_DEPTH) + DECLARE_TEX2D(global_DepthGradient) +#endif + +#if defined(_CUSTOM_SHADOW_COLOR_ON) + float4 global_shadowColor; +#endif + +float4 allIn13DShader_globalTime; + +#if defined(_LIGHTMODEL_FASTLIGHTING) + float3 global_lightDirection; + float4 global_lightColor; +#endif + +#if defined(_WIND_ON) + DECLARE_TEX2D(global_windNoiseTex) + float global_windForce; + float2 global_noiseSpeed; + float global_useWindDir; + float3 global_windDir; + float global_minWindValue; + float global_maxWindValue; + float global_windWorldSize; +#endif +//------------------------ + +#if defined(_SHADINGMODEL_PBR) + #if defined(_METALLIC_MAP_ON) + DECLARE_TEX2D(_MetallicMap) + #endif +#endif + +#if defined(SPECULAR_ON) + DECLARE_TEX2D(_SpecularMap) +#endif + +#if defined(_LIGHTMODEL_TOONRAMP) + DECLARE_TEX2D(_ToonRamp) +#endif + +#if defined(_AOMAP_ON) + DECLARE_TEX2D(_AOMap) +#endif + +#if defined(_SUBSURFACE_SCATTERING_ON) + DECLARE_TEX2D(_SSSMap) +#endif + +#if defined(_FADE_ON) + DECLARE_TEX2D(_FadeTex) +#endif + +#if defined(_VERTEX_DISTORTION_ON) || defined(URP_PASS) + DECLARE_TEX2D(_VertexDistortionNoiseTex) +#endif + +#if defined(_MATCAP_ON) + DECLARE_TEX2D(_MatcapTex) +#endif + +#if defined(_UV_DISTORTION_ON) + DECLARE_TEX2D(_DistortTex) +#endif + +#if defined(_EMISSION_ON) + DECLARE_TEX2D(_EmissionMap) +#endif + +#if defined(_TRIPLANAR_MAPPING_ON) + DECLARE_TEX2D(_TriplanarTopTex) + DECLARE_TEX2D(_TriplanarTopNormalMap) + + #if defined(_TRIPLANAR_NOISE_TRANSITION_ON) + DECLARE_TEX2D(_TriplanarNoiseTex); + #endif +#endif + +#endif //ALLIN13DSHADER_GLOBALPROPERTIESANDTEXTURESDECLARATION \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_GlobalPropertiesAndTexturesDeclaration.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_GlobalPropertiesAndTexturesDeclaration.hlsl.meta new file mode 100644 index 0000000..9a6e660 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_GlobalPropertiesAndTexturesDeclaration.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: b6385c57e3a576042a81507b908422f1 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_GlobalPropertiesAndTexturesDeclaration.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_OutlinePass.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_OutlinePass.hlsl new file mode 100644 index 0000000..1cdf60f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_OutlinePass.hlsl @@ -0,0 +1,140 @@ +#ifndef ALLIN13DSHADER_OUTLINE_PASS_INCLUDED +#define ALLIN13DSHADER_OUTLINE_PASS_INCLUDED + +#if defined(_OUTLINETYPE_SIMPLE) || defined(_OUTLINETYPE_FADEWITHDISTANCE) + #define OUTLINE_FACTOR 0.01 +#else + #define OUTLINE_FACTOR 1.0 +#endif + +float3 GetObjectScale() +{ + float3 res = float3(length(float3(UNITY_MATRIX_M[0].x, UNITY_MATRIX_M[1].x, UNITY_MATRIX_M[2].x)), + length(float3(UNITY_MATRIX_M[0].y, UNITY_MATRIX_M[1].y, UNITY_MATRIX_M[2].y)), + length(float3(UNITY_MATRIX_M[0].z, UNITY_MATRIX_M[1].z, UNITY_MATRIX_M[2].z))); + + return res; +} + +#ifdef OUTLINE_ON +float4 Outline_Constant(float4 vertexPos, float3 normalOS, float3 thicknessScaled) +{ + float3 vertexWS = GetPositionWS(vertexPos); + float3 vertexToCameraWS = _WorldSpaceCameraPos.xyz - vertexWS; + + float distanceToCamera = length(vertexToCameraWS); + + float4 res = vertexPos; + + float normalizedDistanceToCamera = distanceToCamera / ACCESS_PROP_FLOAT(_MaxCameraDistance); + float displacement = thicknessScaled.x * normalizedDistanceToCamera; + res.xyz += normalOS * displacement; + + return res; +} + +float4 Outline_Simple(float4 vertexPos, float3 normalOS, float3 thicknessScaled) +{ + float4 res = vertexPos; + + res.xyz += normalOS * thicknessScaled; + return res; +} + +float4 Outline_FadeWithDistance(float4 vertexPos, float3 normalOS, float3 thicknessScaled) +{ + float4 res = vertexPos; + + float3 vertexWS = GetPositionWS(vertexPos); + float3 vertexToCameraWS = _WorldSpaceCameraPos.xyz - vertexWS; + float distanceToCamera = length(vertexToCameraWS); + + float normalizedDistanceToCamera = saturate(distanceToCamera / ACCESS_PROP_FLOAT(_MaxFadeDistance)); + float3 correctedThickness = (1 - normalizedDistanceToCamera) * thicknessScaled; + + res.xyz += normalOS * correctedThickness; + return res; +} +#endif + +FragmentDataOutline OutlinePass_Vertex(VertexData v) +{ + FragmentDataOutline o; + + o.interpolator_01 = 0; + o.interpolator_02 = 0; + o.interpolator_03 = 0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if defined(OUTLINE_ON) + float3 _Object_Scale = GetObjectScale(); + float3 thicknessScaled = (ACCESS_PROP_FLOAT(_OutlineThickness) / _Object_Scale) * OUTLINE_FACTOR; +#endif + +#if defined(_SPHERIZE_NORMALS_ON) + float3 normalOS = normalize(v.vertex); +#else + float3 normalOS = v.normal; +#endif + +#if defined(_USE_CUSTOM_TIME) + SHADER_TIME(o) = allIn13DShader_globalTime.xyz + ACCESS_PROP_FLOAT(_TimingSeed); +#else + SHADER_TIME(o) = _Time.xyz + ACCESS_PROP_FLOAT(_TimingSeed); +#endif + + v.vertex = ApplyVertexEffects(v.vertex, normalOS, SHADER_TIME(o)); + +#if defined(_OUTLINETYPE_SIMPLE) + v.vertex = Outline_Simple(v.vertex, v.normal, thicknessScaled); +#elif defined(_OUTLINETYPE_CONSTANT) + v.vertex = Outline_Constant(v.vertex, v.normal, thicknessScaled); +#elif defined(_OUTLINETYPE_FADEWITHDISTANCE) + v.vertex = Outline_FadeWithDistance(v.vertex, v.normal, thicknessScaled); +#endif + + o.normalWS = GetNormalWS(v.normal); + o.mainUV = SIMPLE_CUSTOM_TRANSFORM_TEX(v.uv, _MainTex); + o.pos = OBJECT_TO_CLIP_SPACE(v); + o.positionWS = GetPositionWS(v.vertex); + UV_LIGHTMAP(o) = v.uvLightmap; + + FOGCOORD(o) = GetFogFactor(o.pos); + + return o; +} + +float4 OutlinePass_Fragment(FragmentDataOutline i) : SV_Target +{ + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + float4 col = float4(0, 0, 0, 0); + +#ifdef OUTLINE_ON + col = ACCESS_PROP_FLOAT4(_OutlineColor); +#endif + + float camDistance = distance(i.positionWS, _WorldSpaceCameraPos); + float4 screenPos = ComputeScreenPos(i.pos); + col = ApplyAlphaEffects(col, + SCALED_MAIN_UV(i), UV_LIGHTMAP(i), i.positionWS, + 1.0, camDistance, screenPos); + +#ifdef _ALPHA_CUTOFF_ON + clip((col.a - ACCESS_PROP_FLOAT(_AlphaCutoffValue)) - 0.001); +#endif + +#if defined(FOG_ENABLED) + col = CustomMixFog(FOGCOORD(i), col); +#endif + + col.a *= ACCESS_PROP_FLOAT(_GeneralAlpha); + + return col; +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_OutlinePass.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_OutlinePass.hlsl.meta new file mode 100644 index 0000000..32c76df --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_OutlinePass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: bd358394d45cd1d43a4b76562dc0d11b +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_OutlinePass.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShaderFeatures.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShaderFeatures.hlsl new file mode 100644 index 0000000..efb6ee8 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShaderFeatures.hlsl @@ -0,0 +1,104 @@ +#ifndef ALLIN13DSHADER_SHADERFEATURES_ +#define ALLIN13DSHADER_SHADERFEATURES_ + +#pragma shader_feature_local _LIGHTMODEL_NONE +#pragma shader_feature_local _LIGHTMODEL_CLASSIC +#pragma shader_feature_local _LIGHTMODEL_TOON +#pragma shader_feature_local _LIGHTMODEL_TOONRAMP +#pragma shader_feature_local _LIGHTMODEL_HALFLAMBERT +#pragma shader_feature_local _LIGHTMODEL_FAKEGI +#pragma shader_feature_local _LIGHTMODEL_FASTLIGHTING +#pragma shader_feature_local _SHADINGMODEL_BASIC +#pragma shader_feature_local _SHADINGMODEL_PBR +#pragma shader_feature_local _METALLIC_MAP_ON +#pragma shader_feature_local _SPECULARMODEL_NONE +#pragma shader_feature_local _SPECULARMODEL_CLASSIC +#pragma shader_feature_local _SPECULARMODEL_TOON +#pragma shader_feature_local _SPECULARMODEL_ANISOTROPIC +#pragma shader_feature_local _SPECULARMODEL_ANISOTROPICTOON +#pragma shader_feature_local _REFLECTIONS_NONE +#pragma shader_feature_local _REFLECTIONS_CLASSIC +#pragma shader_feature_local _REFLECTIONS_TOON +#pragma shader_feature_local _NORMAL_MAP_ON +#pragma shader_feature_local _FLAT_NORMALS_ON +#pragma shader_feature_local _CUSTOM_SHADOW_COLOR_ON +#pragma shader_feature_local _AFFECTED_BY_LIGHTMAPS_ON +#pragma shader_feature_local _LIGHTMAP_COLOR_CORRECTION_ON +#pragma shader_feature_local _CUSTOM_AMBIENT_LIGHT_ON +#pragma shader_feature_local _CAST_SHADOWS_ON +#pragma shader_feature_local _RECEIVE_SHADOWS_ON +#pragma shader_feature_local _RECEIVEDSHADOWSTYPE_CLASSIC +#pragma shader_feature_local _RECEIVEDSHADOWSTYPE_STYLIZED +#pragma shader_feature_local _COLOR_RAMP_ON +#pragma shader_feature_local _COLORRAMPLIGHTINGSTAGE_BEFORELIGHTING +#pragma shader_feature_local _COLORRAMPLIGHTINGSTAGE_AFTERLIGHTING +#pragma shader_feature_local _AOMAP_ON +#pragma shader_feature_local _HIGHLIGHTS_ON +#pragma shader_feature_local _RIM_LIGHTING_ON +#pragma shader_feature_local _RIMLIGHTINGSTAGE_BEFORELIGHTING +#pragma shader_feature_local _RIMLIGHTINGSTAGE_BEFORELIGHTINGLAST +#pragma shader_feature_local _RIMLIGHTINGSTAGE_AFTERLIGHTING +#pragma shader_feature_local _GREYSCALE_ON +#pragma shader_feature_local _GREYSCALESTAGE_BEFORELIGHTING +#pragma shader_feature_local _GREYSCALESTAGE_AFTERLIGHTING +#pragma shader_feature_local _POSTERIZE_ON +#pragma shader_feature_local _HUE_SHIFT_ON +#pragma shader_feature_local _EMISSION_ON +#pragma shader_feature_local _HOLOGRAM_ON +#pragma shader_feature_local _MATCAP_ON +#pragma shader_feature_local _MATCAPBLENDMODE_MULTIPLY +#pragma shader_feature_local _MATCAPBLENDMODE_REPLACE +#pragma shader_feature_local _HIT_ON +#pragma shader_feature_local _CONTRAST_BRIGHTNESS_ON +#pragma shader_feature_local _HEIGHT_GRADIENT_ON +#pragma shader_feature_local _HEIGHTGRADIENTPOSITIONSPACE_LOCAL +#pragma shader_feature_local _HEIGHTGRADIENTPOSITIONSPACE_WORLD +#pragma shader_feature_local _INTERSECTION_GLOW_ON +#pragma shader_feature_local _ALBEDO_VERTEX_COLOR_ON +#pragma shader_feature_local _ALBEDOVERTEXCOLORMODE_MULTIPLY +#pragma shader_feature_local _ALBEDOVERTEXCOLORMODE_REPLACE +#pragma shader_feature_local _TRIPLANAR_MAPPING_ON +#pragma shader_feature_local _TRIPLANARNORMALSPACE_LOCAL +#pragma shader_feature_local _TRIPLANARNORMALSPACE_WORLD +#pragma shader_feature_local _TRIPLANAR_NOISE_TRANSITION_ON +#pragma shader_feature_local _TEXTURE_BLENDING_ON +#pragma shader_feature_local _TEXTUREBLENDINGSOURCE_VERTEXCOLOR +#pragma shader_feature_local _TEXTUREBLENDINGSOURCE_TEXTURE +#pragma shader_feature_local _TEXTUREBLENDINGMODE_RGB +#pragma shader_feature_local _TEXTUREBLENDINGMODE_BLACKANDWHITE +#pragma shader_feature_local _DEPTH_COLORING_ON +#pragma shader_feature_local _SUBSURFACE_SCATTERING_ON +#pragma shader_feature_local _ALPHA_CUTOFF_ON +#pragma shader_feature_local _FADE_ON +#pragma shader_feature_local _FADEUVSET_UV1 +#pragma shader_feature_local _FADEUVSET_UV2 +#pragma shader_feature_local _FADEUVSET_WORLD_SPACE +#pragma shader_feature_local _FADE_BURN_ON +#pragma shader_feature_local _INTERSECTION_FADE_ON +#pragma shader_feature_local _ALPHA_ROUND_ON +#pragma shader_feature_local _FADE_BY_CAM_DISTANCE_ON +#pragma shader_feature_local _FADE_BY_CAM_DISTANCE_NEAR_FADE +#pragma shader_feature_local _DITHER_ON +#pragma shader_feature_local _VERTEX_SHAKE_ON +#pragma shader_feature_local _VERTEX_INFLATE_ON +#pragma shader_feature_local _VERTEX_DISTORTION_ON +#pragma shader_feature_local _VOXELIZE_ON +#pragma shader_feature_local _GLITCH_ON +#pragma shader_feature_local _RECALCULATE_NORMALS_ON +#pragma shader_feature_local _WIND_ON +#pragma shader_feature_local _USE_WIND_VERTICAL_MASK +#pragma shader_feature_local _SCROLL_TEXTURE_ON +#pragma shader_feature_local _SCREEN_SPACE_UV_ON +#pragma shader_feature_local _PIXELATE_ON +#pragma shader_feature_local _STOCHASTIC_SAMPLING_ON +#pragma shader_feature_local _WAVE_UV_ON +#pragma shader_feature_local _HAND_DRAWN_ON +#pragma shader_feature_local _UV_DISTORTION_ON +#pragma shader_feature_local _OUTLINETYPE_NONE +#pragma shader_feature_local _OUTLINETYPE_SIMPLE +#pragma shader_feature_local _OUTLINETYPE_CONSTANT +#pragma shader_feature_local _OUTLINETYPE_FADEWITHDISTANCE +#pragma shader_feature_local _FOG_ON + + +#endif //ALLIN13DSHADER_SHADERFEATURES_ \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShaderFeatures.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShaderFeatures.hlsl.meta new file mode 100644 index 0000000..6e3406f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShaderFeatures.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 9c2f0a067529e8f4ebff5b3d9b328a73 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShaderFeatures.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl new file mode 100644 index 0000000..fd91ce1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl @@ -0,0 +1,78 @@ +#ifndef ALLIN13DSHADER_SHADOW_CASTER_PASS_INCLUDED +#define ALLIN13DSHADER_SHADOW_CASTER_PASS_INCLUDED + +FragmentDataShadowCaster BasicVertexShadowCaster(VertexData v) +{ + FragmentDataShadowCaster o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#ifdef _USE_CUSTOM_TIME + float3 shaderTime = allIn13DShader_globalTime.xyz + ACCESS_PROP_FLOAT(_TimingSeed); +#else + float3 shaderTime = _Time.xyz + ACCESS_PROP_FLOAT(_TimingSeed); +#endif + + v.vertex = ApplyVertexEffects(v.vertex, v.normal, shaderTime); + + + float2 uv = v.uv; + uv = ApplyUVEffects_VertexStage(uv, o.positionWS, 0, shaderTime); + + o.mainUV.xy = SIMPLE_CUSTOM_TRANSFORM_TEX(uv, _MainTex); + o.positionOS = v.vertex; + o.positionWS = GetPositionWS(v.vertex); + o.uv2 = v.uvLightmap; + o.shaderTime = shaderTime; + o.normalOS = v.normal; + o.normalWS = GetNormalWS(v.normal); + + + o = GetClipPosShadowCaster(v, o); + + return o; +} + +float4 BasicFragmentShadowCaster(FragmentDataShadowCaster i) : SV_Target +{ + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + +#if !defined(_CAST_SHADOWS_ON) + #if defined(BIRP_PASS) + if (unity_LightShadowBias.z != 0.0) discard; + #else + discard; + #endif +#endif + + EffectsData data = CalculateEffectsData_ShadowCaster(i); + data = ApplyUVEffects_FragmentStage(data); + + float4 col = SAMPLE_TEX2D(_MainTex, i.mainUV.xy); + + + float camDistance = distance(i.positionWS, _WorldSpaceCameraPos); + + float4 screenPos = ComputeScreenPos(i.pos); + + col = ApplyAlphaEffects(col, + i.mainUV, i.uv2, data.vertexWS, + 1.0, camDistance, screenPos); + + col.a *= ACCESS_PROP_FLOAT(_GeneralAlpha); + + float alphaClip = saturate(col.a); +#ifdef _ALPHA_CUTOFF_ON + alphaClip -= ACCESS_PROP_FLOAT(_AlphaCutoffValue); +#endif + + clip(alphaClip - 0.001); + + return 0; +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl.meta new file mode 100644 index 0000000..5e5161b --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 4039a3685bcd9c247ae99b74dc66ca82 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_ShadowCasterPass.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl new file mode 100644 index 0000000..84daa1f --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl @@ -0,0 +1,150 @@ +#ifndef ALLIN13DSHADER_URP_DEPTH_NORMALS_PASS_INCLUDED +#define ALLIN13DSHADER_URP_DEPTH_NORMALS_PASS_INCLUDED + + struct DepthNormalsVertexData + { + float4 positionOS : POSITION; + float3 normal : NORMAL; + float2 uv : TEXCOORD0; + float2 uvLightmap : TEXCOORD1; + float4 tangent : TANGENT; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct DepthNormalsFragmentData + { + float4 positionCS : SV_POSITION; + float3 normalWS : TEXCOORD1; + float4 mainUV : TEXCOORD2; + float4 interpolator_01 : TEXCOORD3; + float4 interpolator_02 : TEXCOORD4; + +#ifdef REQUIRE_SCENE_DEPTH + float4 projPos : TEXCOORD5; +#endif + + float3 positionWS : TEXCOORD6; + +#ifdef REQUIRE_TANGENT_WS + T_SPACE_PROPERTIES(7, 8, 9) +#endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + DepthNormalsFragmentData DepthNormalsVertex(DepthNormalsVertexData input) + { + DepthNormalsFragmentData o; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + o.interpolator_01 = float4(0, 0, 0, 0); + o.interpolator_02 = float4(0, 0, 0, 0); + o.mainUV = float4(0, 0, 0, 0); + SCALED_MAIN_UV(o) = CUSTOM_TRANSFORM_TEX(input.uv, UV_DIFF(o), _MainTex); + UV_LIGHTMAP(o) = input.uvLightmap; + +#ifdef _SPHERIZE_NORMALS_ON + float3 normalOS = normalize(input.positionOS); +#else + float3 normalOS = input.normal; +#endif + +#ifdef _USE_CUSTOM_TIME + float3 shaderTime = allIn13DShader_globalTime.xyz + ACCESS_PROP_FLOAT(_TimingSeed); +#else + float3 shaderTime = _Time.xyz + ACCESS_PROP_FLOAT(_TimingSeed); +#endif + + input.positionOS = ApplyVertexEffects(input.positionOS, normalOS, shaderTime); + + o.positionCS = TransformObjectToHClip(input.positionOS.xyz); + o.normalWS = GetNormalWS(input.normal); + o.positionWS = GetPositionWS(input.positionOS); + +#if defined(REQUIRE_TANGENT_WS) + float3 tangentWS = GetDirWS(float4(input.tangent.xyz, 0)); + float3 bitangentWS = GetBitangentWS(input.tangent, tangentWS, o.normalWS); + INIT_T_SPACE(o.normalWS) + + UV_NORMAL_MAP(o) = CUSTOM_TRANSFORM_TEX(input.uv, UV_DIFF(o), _NormalMap); +#endif + + + + float4 projPos = 0; +#ifdef REQUIRE_SCENE_DEPTH + o.projPos = ComputeScreenPos(o.positionCS); + + float3 positionWS = GetPositionWS(input.positionOS); + o.projPos.z = ComputeEyeDepth(positionWS); + projPos = o.projPos; +#endif + + return o; + } + + float4 DepthNormalsFragment( + DepthNormalsFragmentData input + #ifdef _WRITE_RENDERING_LAYERS + #if UNITY_VERSION >= 60020000 + , out uint outRenderingLayers : SV_Target1 + #else + , out float4 outRenderingLayers : SV_Target1 + #endif + #endif + ) : SV_TARGET + { + UNITY_SETUP_INSTANCE_ID(input); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); + + float4 baseColor = SAMPLE_TEX2D(_MainTex, input.mainUV.xy); + + float3 normalWS = normalize(input.normalWS); + float4 res = float4(normalWS, 1.0); + + #ifdef _NORMAL_MAP_ON + float3 tangentWS = normalize(TANGENT_WS(input)); + float3 bitangentWS = normalize(cross(normalWS, tangentWS)); + + float4 sampledNormal = SAMPLE_TEX2D(_NormalMap, input.mainUV); + + float3 tnormal = UnpackNormal(sampledNormal); + tnormal.xy *= ACCESS_PROP_FLOAT(_NormalStrength); + + res.x = dot(input.tspace0, tnormal); + res.y = dot(input.tspace1, tnormal); + res.z = dot(input.tspace2, tnormal); + + res = normalize(res); + res.w = 0; + #endif + + float camDistance = distance(input.positionWS, _WorldSpaceCameraPos); + float4 screenPos = ComputeScreenPos(input.positionCS); + baseColor = ApplyAlphaEffects(baseColor, + SCALED_MAIN_UV(input), UV_LIGHTMAP(input), input.positionWS, + 1.0, camDistance, screenPos); + + float alphaClip = saturate(baseColor.a); + #ifdef _ALPHA_CUTOFF_ON + clip((alphaClip - ACCESS_PROP_FLOAT(_AlphaCutoffValue)) - 0.01); + #endif + + #if defined(_WRITE_RENDERING_LAYERS) + #if UNITY_VERSION >= 60020000 + outRenderingLayers = EncodeMeshRenderingLayer(); + #else + uint renderingLayers = AllIn1GetMeshRenderingLayer(); + outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0); + #endif + #endif + + return res; + } + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl.meta new file mode 100644 index 0000000..dfac6a3 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: cee3f31d4e663a84c83d7cb65d3af22b +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthNormalsPass.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl new file mode 100644 index 0000000..65853e1 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl @@ -0,0 +1,65 @@ +#ifndef ALLIN13DSHADER_URP_DEPTHONLYPASS +#define ALLIN13DSHADER_URP_DEPTHONLYPASS + +struct DepthOnlyVertexData +{ + float4 positionOS : POSITION; + float2 uv : TEXCOORD0; + float2 uvLightmap : TEXCOORD1; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct DepthOnlyFragmentData +{ + float4 positionCS : SV_POSITION; + float3 positionWS : TEXCOORD1; + float4 mainUV : TEXCOORD2; + float4 interpolator_01 : TEXCOORD3; + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO +}; + +DepthOnlyFragmentData DepthOnlyVertex(DepthOnlyVertexData input) +{ + DepthOnlyFragmentData res; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, res); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(res); + + res.interpolator_01 = float4(0, 0, 0, 0); + res.mainUV = float4(0, 0, 0, 0); + UV_LIGHTMAP(res) = input.uvLightmap; + SCALED_MAIN_UV(res) = CUSTOM_TRANSFORM_TEX(input.uv, UV_DIFF(res), _MainTex); + + res.positionWS = GetPositionWS(input.positionOS); + res.positionCS = TransformObjectToHClip(input.positionOS.xyz); + + return res; +} + +float DepthOnlyFragment(DepthOnlyFragmentData input) : SV_TARGET +{ + UNITY_SETUP_INSTANCE_ID(input); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); + + float4 screenPos = ComputeScreenPos(input.positionCS); + float camDistance = distance(input.positionWS, _WorldSpaceCameraPos); + float4 baseColor = SAMPLE_TEX2D(_MainTex, input.mainUV.xy); + baseColor = ApplyAlphaEffects(baseColor, + SCALED_MAIN_UV(input), UV_LIGHTMAP(input), input.positionWS, + 1.0, camDistance, screenPos); + + float alphaClip = saturate(baseColor.a); + #ifdef _ALPHA_CUTOFF_ON + clip((alphaClip - ACCESS_PROP_FLOAT(_AlphaCutoffValue)) - 0.01); + #endif + + + + + return input.positionCS.z; +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl.meta new file mode 100644 index 0000000..be72d42 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 6ed0ae91c0725fb4fb02d352183233aa +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_DepthOnlyPass.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl new file mode 100644 index 0000000..394e764 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl @@ -0,0 +1,61 @@ +#ifndef ALLIN13DSHADER_URP_METAPASS +#define ALLIN13DSHADER_URP_METAPASS + +struct Attributes +{ + float4 positionOS : POSITION; + float3 normalOS : NORMAL; + float2 uv0 : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float2 uv2 : TEXCOORD2; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct Varyings +{ + float4 positionCS : SV_POSITION; + float2 uv : TEXCOORD0; +#ifdef EDITOR_VISUALIZATION + float2 VizUV : TEXCOORD1; + float4 LightCoord : TEXCOORD2; +#endif +}; + +//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UniversalMetaPass.hlsl" +#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl" + + +Varyings AllIn1VertexMeta(Attributes input) +{ + Varyings output = (Varyings)0; + output.positionCS = UnityMetaVertexPosition(input.positionOS.xyz, input.uv1, input.uv2); + //output.uv = TRANSFORM_TEX(input.uv0, _BaseMap); + output.uv = input.uv0; +#ifdef EDITOR_VISUALIZATION + UnityEditorVizData(input.positionOS.xyz, input.uv0, input.uv1, input.uv2, output.VizUV, output.LightCoord); +#endif + return output; +} + +half4 AllIn1FragmentMeta(Varyings input) : SV_Target +{ + float2 uv = input.uv; + + MetaInput metaInput; + metaInput.Albedo = ACCESS_PROP_FLOAT4(_Color).rgb * SAMPLE_TEXTURE2D(_MainTex, sampler__MainTex, uv).rgb; + + metaInput.Emission = float3(0, 0, 0); +#ifdef _EMISSION_ON + metaInput.Emission = SAMPLE_TEX2D(_EmissionMap, uv) * ACCESS_PROP_FLOAT4(_EmissionColor) * ACCESS_PROP_FLOAT(_EmissionSelfGlow); +#endif + +#ifdef EDITOR_VISUALIZATION + metaInput.VizUV = input.VizUV; + metaInput.LightCoord = input.LightCoord; +#endif + + float4 res = UnityMetaFragment(metaInput); + return res; +} + +#endif //Directional Lightmaps \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl.meta new file mode 100644 index 0000000..366e0e2 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: d65cbf5bc1a04414395a9adf70ae01ba +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_URP_MetaPass.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_UVEffects.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_UVEffects.hlsl new file mode 100644 index 0000000..563c237 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_UVEffects.hlsl @@ -0,0 +1,213 @@ +#ifndef ALLIN13DSHADER_UV_EFFECTS +#define ALLIN13DSHADER_UV_EFFECTS + +#ifdef _SCROLL_TEXTURE_ON +// +float2 ScrollTexture(float2 inputUV, float3 shaderTime) +{ + float2 res = inputUV; + + res.x += (shaderTime.x * ACCESS_PROP_FLOAT(_ScrollTextureX)) % 1; + res.y += (shaderTime.x * ACCESS_PROP_FLOAT(_ScrollTextureY)) % 1; + + return res; +} +// +#endif + +#ifdef _WAVE_UV_ON +// +// +EffectsData WaveUV(EffectsData data) +{ + EffectsData res = data; + + float2 uvWaveDiff = float2(ACCESS_PROP_FLOAT(_WaveX) * ACCESS_PROP_FLOAT4(_MainTex_ST).x, ACCESS_PROP_FLOAT(_WaveY) * ACCESS_PROP_FLOAT4(_MainTex_ST).y) - res.mainUV; + + uvWaveDiff.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = data.shaderTime.y; + float angWave = (sqrt(dot(uvWaveDiff, uvWaveDiff)) * ACCESS_PROP_FLOAT(_WaveAmount)) - ((waveTime * ACCESS_PROP_FLOAT(_WaveSpeed) % 360.0)); + + uvWaveDiff = normalize(uvWaveDiff) * sin(angWave) * (ACCESS_PROP_FLOAT(_WaveStrength) / 1000.0); + DISPLACE_ALL_UVS(res, uvWaveDiff); + + return res; +} +// +#endif + +#ifdef _SCREEN_SPACE_UV_ON +float2 ScreenSpaceUV(float2 inputUV, float3 vertexWS, float4 projPos) +{ + float2 res = inputUV; + + float aspect = _ScreenParams.x / _ScreenParams.y; + + float4 pivotCS = OBJECT_TO_CLIP_SPACE_FLOAT4(float4(0, 0, 0, 1)); + pivotCS.xy /= pivotCS.w; + pivotCS.y *= -1; + pivotCS.xy += 1.0; + pivotCS.xy *= 0.5; + + float3 positionVS = mul(UNITY_MATRIX_V, float4(vertexWS, 1.0)).xyz; + + float2 screenUV = (projPos.xy / projPos.w); + screenUV -= 0.5; + screenUV.x *= aspect; + + + float2 screenUVMinusPivot = screenUV - pivotCS.xy; + float2 stableUVs = (screenUV - pivotCS.xy + 0.5) * -positionVS.z; + stableUVs *= 0.1; + + res = lerp(screenUV, stableUVs, ACCESS_PROP_FLOAT(_ScaleWithCameraDistance)); + return res; +} +#endif + +#ifdef _HAND_DRAWN_ON +// +float2 HandDrawn(float2 inputUV, float3 shaderTime) +{ + float2 uvCopy = inputUV; + float2 res = inputUV; + + + float drawnSpeed = (floor(frac(shaderTime.x) * 20 * ACCESS_PROP_FLOAT(_HandDrawnSpeed)) / ACCESS_PROP_FLOAT(_HandDrawnSpeed)) * ACCESS_PROP_FLOAT(_HandDrawnSpeed); + uvCopy.x = sin((uvCopy.x * ACCESS_PROP_FLOAT(_HandDrawnAmount) + drawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * ACCESS_PROP_FLOAT(_HandDrawnAmount) + drawnSpeed) * 4); + res = lerp(res, res + uvCopy, 0.0005 * ACCESS_PROP_FLOAT(_HandDrawnAmount)); + + return res; +} +// +#endif + + +#ifdef _TRIPLANAR_MAPPING_ON +EffectsData TriplanarMapping(EffectsData input) +{ + EffectsData res = input; + + float2 uvDiff = input.uvDiff; + + #ifdef _TRIPLANARNORMALSPACE_LOCAL + float3 normal = res.normalOS; + float3 position = res.vertexOS; + #else + float3 normal = res.normalWS; + float3 position = res.vertexWS; + + uvDiff *= 10.0; + #endif + + float3 triplanarWeights = GetTriplanarWeights(normal, input.mainUV); + + float2 positionXY = position.xy; + float2 positionZY = position.zy; + float2 positionXZ = position.xz; + + res.uvMatrix._m00_m01 = CUSTOM_TRANSFORM_TEX(positionXY, uvDiff, _MainTex); //Front + res.uvMatrix._m02 = triplanarWeights.z; + + res.uvMatrix._m10_m11 = CUSTOM_TRANSFORM_TEX(positionZY, uvDiff, _MainTex); //Side + res.uvMatrix._m12 = triplanarWeights.x; + + res.uvMatrix._m20_m21 = CUSTOM_TRANSFORM_TEX(positionXZ, uvDiff, _TriplanarTopTex); //Top + res.uvMatrix._m22 = triplanarWeights.y; + + res.uvMatrix._m30_m31 = CUSTOM_TRANSFORM_TEX(positionXZ, uvDiff, _MainTex); //Down + res.uvMatrix._m32 = 1 - normal.y; + +#ifdef _NORMAL_MAP_ON + float2 frontUV_normal_Z = CUSTOM_TRANSFORM_TEX(position.xy, uvDiff, _MainTex); //Front - Z facing plane + float2 sideUV_normal_X = CUSTOM_TRANSFORM_TEX(position.zy, uvDiff, _MainTex); //Side - X facing plane + float2 topUV_normal_Y = CUSTOM_TRANSFORM_TEX(position.xz, uvDiff, _TriplanarTopTex); //Top - Y facing plane + + res.uv_matrix_normalMap._m00_m01 = frontUV_normal_Z; //Front + res.uv_matrix_normalMap._m02 = triplanarWeights.z; + + res.uv_matrix_normalMap._m10_m11 = sideUV_normal_X; //Side + res.uv_matrix_normalMap._m12 = triplanarWeights.x; + + res.uv_matrix_normalMap._m20_m21 = topUV_normal_Y; //Top + res.uv_matrix_normalMap._m22 = triplanarWeights.y; +#endif + + return res; +} +#endif + +#ifdef _UV_DISTORTION_ON +// +EffectsData UVDistortion(EffectsData data) +{ + EffectsData res = data; + + float2 distortTexUV = data.uv_dist; + + distortTexUV.x += frac((data.shaderTime.x) * ACCESS_PROP_FLOAT(_DistortTexXSpeed)); + distortTexUV.y += frac((data.shaderTime.x) * ACCESS_PROP_FLOAT(_DistortTexYSpeed)); + + float4 distortTexCol = SAMPLE_TEX2D_LOD(_DistortTex, float4(distortTexUV.x, distortTexUV.y, 0, 0)); + float distortAmnt = (distortTexCol.r - 0.5) * 0.2 * ACCESS_PROP_FLOAT(_DistortAmount); + + DISPLACE_ALL_UVS(res, distortAmnt); + + return res; +} +// +#endif + +#ifdef _PIXELATE_ON +// +EffectsData Pixelate(EffectsData data) +{ + EffectsData res = data; + + half aspectRatio = ACCESS_PROP_FLOAT4(_MainTex_TexelSize).x / ACCESS_PROP_FLOAT4(_MainTex_TexelSize).y; + half2 pixelSize = float2(ACCESS_PROP_FLOAT(_PixelateSize), ACCESS_PROP_FLOAT(_PixelateSize) * aspectRatio); + + QUANTIZE_ALL_UVS(res, pixelSize) + return res; +} +// +#endif + +//#ifdef _STOCHASTIC_SAMPLING_ON +//EffectsData StochasticSamplingOn(EffectsData data) +//{ +// EffectsData res = data; + +// float2 UV = MAIN_UV(data); + +// //triangle vertices and blend weights +// //BW_vx[0...2].xyz = triangle verts +// //BW_vx[3].xy = blend weights (z is unused) +// float4x3 BW_vx; + +// //uv transformed into triangular grid space with UV scaled by approximation of 2*sqrt(3) +// float2 skewUV = mul(float2x2 (1.0 , 0.0 , -0.57735027 , 1.15470054), UV * 3.464); + +// //vertex IDs and barycentric coords +// float2 vxID = float2 (floor(skewUV)); +// float3 barry = float3 (frac(skewUV), 0); +// barry.z = 1.0-barry.x-barry.y; + +// BW_vx = ((barry.z>0) ? +// float4x3(float3(vxID, 0), float3(vxID + float2(0, 1), 0), float3(vxID + float2(1, 0), 0), barry.zyx) : +// float4x3(float3(vxID + float2 (1, 1), 0), float3(vxID + float2 (1, 0), 0), float3(vxID + float2 (0, 1), 0), float3(-barry.z, 1.0-barry.y, 1.0-barry.x))); + +// //calculate derivatives to avoid triangular grid artifacts +// float2 dx = ddx(UV); +// float2 dy = ddy(UV); + +// float4 newUVs = mul(tex2D(tex, UV + hash2D2D(BW_vx[0].xy), dx, dy), BW_vx[3].x) + +// mul(tex2D(tex, UV + hash2D2D(BW_vx[1].xy), dx, dy), BW_vx[3].y) + +// mul(tex2D(tex, UV + hash2D2D(BW_vx[2].xy), dx, dy), BW_vx[3].z); + +// return res; +//} +//#endif + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_UVEffects.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_UVEffects.hlsl.meta new file mode 100644 index 0000000..e934306 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_UVEffects.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: d61ca1c3b2921b4458b28e3b02288808 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_UVEffects.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_VertexEffects.hlsl b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_VertexEffects.hlsl new file mode 100644 index 0000000..22da0ea --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_VertexEffects.hlsl @@ -0,0 +1,138 @@ +#ifndef ALLIN13DSHADER_VERTEX_EFFECTS +#define ALLIN13DSHADER_VERTEX_EFFECTS + +#ifdef _VERTEX_SHAKE_ON +float3 VertexShake(float3 vertexPos, float3 shaderTime) +{ + float3 res = vertexPos; + + float3 speedOffset = float3(1.0f, 1.13f, 1.07f) * ACCESS_PROP_FLOAT(_ShakeSpeedMult); + float3 displacement = sin(shaderTime.y * ACCESS_PROP_FLOAT4(_ShakeSpeed).xyz * speedOffset) * ACCESS_PROP_FLOAT4(_ShakeMaxDisplacement).xyz; + displacement *= ACCESS_PROP_FLOAT(_ShakeBlend); + + res += displacement; + + return res; +} +#endif + +#ifdef _VERTEX_INFLATE_ON +float3 VertexInflate(float3 vertexPos, float3 normalOS, float3 shaderTime) +{ + float3 res = vertexPos; + + float inflateValue = lerp(ACCESS_PROP_FLOAT(_MinInflate), ACCESS_PROP_FLOAT(_MaxInflate), ACCESS_PROP_FLOAT(_InflateBlend)); + res += normalOS * inflateValue; + + return res; +} +#endif + +#ifdef _VERTEX_DISTORTION_ON +float3 VertexDistortion(float3 vertexPos, float3 normalOS, float3 shaderTime) +{ + float3 res = vertexPos; + + float noisePower = 1.0; + + float2 noiseUV = SIMPLE_CUSTOM_TRANSFORM_TEX(vertexPos.xy, _VertexDistortionNoiseTex); + float4 correctedNoiseUV = float4(noiseUV.x, noiseUV.y, 0, 0); + + correctedNoiseUV.x += frac(shaderTime.x * ACCESS_PROP_FLOAT(_VertexDistortionNoiseSpeedX)); + correctedNoiseUV.y += frac(shaderTime.x * ACCESS_PROP_FLOAT(_VertexDistortionNoiseSpeedY)); + + noisePower = SAMPLE_TEX2D_LOD(_VertexDistortionNoiseTex, correctedNoiseUV).r; + + res += normalOS * noisePower * ACCESS_PROP_FLOAT(_VertexDistortionAmount); + + return res; +} +#endif + +#ifdef _VOXELIZE_ON +float3 VertexVoxel(float3 vertexPos) +{ + float3 voxelizedPosition = round(vertexPos * ACCESS_PROP_FLOAT(_VoxelSize)) / ACCESS_PROP_FLOAT(_VoxelSize); + return lerp(vertexPos, voxelizedPosition, ACCESS_PROP_FLOAT(_VoxelBlend)); +} +#endif + +#ifdef _GLITCH_ON +float3 Glitch(float3 vertexPos, float3 shaderTime) +{ + float3 res = vertexPos; + + float3 glitchDir = GetDirOSFloat3(ACCESS_PROP_FLOAT3(_GlitchOffset)); + + float3 scale = float3(length(OBJECT_TO_WORLD_MATRIX[0].xyz), + length(OBJECT_TO_WORLD_MATRIX[1].xyz), + length(OBJECT_TO_WORLD_MATRIX[2].xyz)); + float pos = ACCESS_PROP_FLOAT(_GlitchWorldSpace) ? mul(OBJECT_TO_WORLD_MATRIX, float4(vertexPos, 1.0)).y : vertexPos.y; + float time = shaderTime.y * ACCESS_PROP_FLOAT(_GlitchSpeed); + + // Add high frequency noise to the main UV + float2 glitchUV = float2(pos * ACCESS_PROP_FLOAT(_GlitchTiling) + time, time * 0.89); + float mainNoise = noise2D(glitchUV); + float fastNoise = noise2D(glitchUV * 2.5 + float2(time * 3.7, 0)); + mainNoise = mainNoise * 0.6 + fastNoise * 0.4; + + float2 periodicUV = float2(time * 0.5, time * 0.14); + float periodicNoise = saturate(noise2D(periodicUV) + 0.1); + + float detailNoise = noise2D(float2(20.0 * glitchUV.x, glitchUV.y)); + + float glitchValue = (2.0 * mainNoise - 1.0) * periodicNoise; + glitchValue += glitchValue * lerp(0, saturate(2.0 * detailNoise - 1.0), 2.0); + + res += (glitchDir / scale) * glitchValue * ACCESS_PROP_FLOAT(_GlitchAmount); + + return res; +} +#endif + +#ifdef _RECALCULATE_NORMALS_ON +float3 RecalculateNormal(float3 originalVertex, float3 normal, float3 tangent) +{ + return normal; +} +#endif + +#ifdef _WIND_ON +float3 Wind(float3 vertexPos, float3 shaderTime) +{ + float3 res = vertexPos; + + float windMask = 1.0; + #ifdef _USE_WIND_VERTICAL_MASK + windMask = RemapFloat(vertexPos.y, ACCESS_PROP_FLOAT(_WindVerticalMaskMinY), ACCESS_PROP_FLOAT(_WindVerticalMaskMaxY), 0, 1); + #endif + + float3 vertexWS = GetPositionWS(float4(vertexPos, 1.0)); + + float2 windNoiseUV = float2(vertexWS.x, vertexWS.z) / global_windWorldSize; + windNoiseUV += global_noiseSpeed * shaderTime.x; + windNoiseUV = frac(windNoiseUV); + + float3 windNoise = SAMPLE_TEX2D_LOD(global_windNoiseTex, float4(windNoiseUV.x, windNoiseUV.y, 0, 0)); + windNoise = RemapFloat3(windNoise, 0, 1, global_minWindValue, global_maxWindValue); + + if(global_useWindDir) + { + windNoise = (windNoise.x + windNoise.y + windNoise.z) / 3; + } + + float3 windDisplacement = windNoise * global_windForce * windMask * global_windDir; + windDisplacement = lerp(0, windDisplacement, ACCESS_PROP_FLOAT(_WindAttenuation)); + + windDisplacement.y = 0; + + float3 positionWS = GetPositionWS(float4(res, 1.0)); + positionWS += windDisplacement; + + res = GetPositionOS(float4(positionWS, 1.0)); + + return res; +} +#endif + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_VertexEffects.hlsl.meta b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_VertexEffects.hlsl.meta new file mode 100644 index 0000000..f512d02 --- /dev/null +++ b/Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_VertexEffects.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 6d625c6ff0d698c4cad5f90150312f70 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 316173 + packageName: All In 1 3D-Shader + packageVersion: 2.72 + assetPath: Assets/Plugins/AllIn13DShader/Shaders/ShaderLibrary/AllIn13DShader_VertexEffects.hlsl + uploadId: 865720 diff --git a/Assets/Plugins/AllIn1SpriteShader.meta b/Assets/Plugins/AllIn1SpriteShader.meta new file mode 100644 index 0000000..6c140a2 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 151483ddcae0bba4da530432cab5e818 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/AllIn1SpriteShaderAssembly.asmdef b/Assets/Plugins/AllIn1SpriteShader/AllIn1SpriteShaderAssembly.asmdef new file mode 100644 index 0000000..80a821f --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/AllIn1SpriteShaderAssembly.asmdef @@ -0,0 +1,17 @@ +{ + "name": "AllIn1SpriteShaderAssembly", + "rootNamespace": "", + "references": [ + "GUID:7ab3663edede26740845931880bf22af", + "GUID:75469ad4d38634e559750d17036d5f7c" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/AllIn1SpriteShaderAssembly.asmdef.meta b/Assets/Plugins/AllIn1SpriteShader/AllIn1SpriteShaderAssembly.asmdef.meta new file mode 100644 index 0000000..c4fae09 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/AllIn1SpriteShaderAssembly.asmdef.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 91de482a0a233614ab5962ea5f6c24ee +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/AllIn1SpriteShaderAssembly.asmdef + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Materials.meta b/Assets/Plugins/AllIn1SpriteShader/Materials.meta new file mode 100644 index 0000000..2637c87 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Materials.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 345f2705e87e7424683ef2bd17d38c26 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Materials/EmptyMaterial.mat b/Assets/Plugins/AllIn1SpriteShader/Materials/EmptyMaterial.mat new file mode 100644 index 0000000..6b63a79 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Materials/EmptyMaterial.mat @@ -0,0 +1,178 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: EmptyMaterial + m_Shader: {fileID: 4800000, guid: a36b7719ff0465b42ab1407d67672c5f, type: 3} + m_ShaderKeywords: ETC1_EXTERNAL_ALPHA + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _ColorRampTex: + m_Texture: {fileID: 2800000, guid: 279657edc397ece4b8029c727adf6ddc, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ColorSwapTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DistortTex: + m_Texture: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _FadeBurnTex: + m_Texture: {fileID: 2800000, guid: 32e8df0008bebe746b1681a71c61f31c, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _FadeTex: + m_Texture: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _GlowTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OutlineDistortTex: + m_Texture: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OutlineTex: + m_Texture: {fileID: 2800000, guid: 74087f6d03f233e4a8a142fa01f9e5cf, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _Alpha: 1 + - _AlphaCutoffValue: 0.25 + - _BlurHD: 0 + - _BlurIntensity: 10 + - _ChromAberrAlpha: 0.4 + - _ChromAberrAmount: 1 + - _ClipUvDown: 1 + - _ClipUvLeft: 1 + - _ClipUvRight: 1 + - _ClipUvUp: 1 + - _ColorChangeLuminosity: 0 + - _ColorChangeTolerance: 0.25 + - _ColorRampLuminosity: 0 + - _ColorRampOutline: 0 + - _ColorSwapBlueLuminosity: 0.5 + - _ColorSwapGreenLuminosity: 0.5 + - _ColorSwapRedLuminosity: 0.5 + - _DistortAmount: 0.5 + - _DistortTexXSpeed: 5 + - _DistortTexYSpeed: 5 + - _FadeAmount: -0.1 + - _FadeBurnGlow: 2 + - _FadeBurnTransition: 0.075 + - _FadeBurnWidth: 0.025 + - _FishEyeUvAmount: 0.35 + - _FlickerAlpha: 0 + - _FlickerFreq: 0.2 + - _FlickerPercent: 0.05 + - _GhostColorBoost: 1 + - _GhostTransparency: 0 + - _GlitchAmount: 3 + - _Glow: 0 + - _GlowTexUsed: 0 + - _GradBlend: 1 + - _GrassManualAnim: 1 + - _GrassManualToggle: 0 + - _GrassSpeed: 2 + - _GrassWind: 20 + - _GreyscaleLuminosity: 0 + - _GreyscaleOutline: 0 + - _HandDrawnAmount: 10 + - _HandDrawnSpeed: 5 + - _HitEffectBlend: 1 + - _HitEffectGlow: 5 + - _HologramFlickerAlpha: 0 + - _HologramFlickerFreq: 0.2 + - _HologramFlickerPercent: 0.05 + - _HologramStripesAlpha: 0.4 + - _HologramStripesAmount: 50 + - _HologramStripesFill: 0.4 + - _HologramStripesLuminosity: 1 + - _HologramStripesSpeed: 5 + - _HsvBright: 1 + - _HsvSaturation: 1 + - _HsvShift: 180 + - _InnerOutlineAlpha: 1 + - _InnerOutlineGlow: 1 + - _InnerOutlineThickness: 1 + - _MotionBlurAngle: 0.1 + - _MotionBlurDist: 1.25 + - _NegativeAmount: 1 + - _OffsetUvX: 0 + - _OffsetUvY: 0 + - _Outline8Directions: 0 + - _OutlineAlpha: 1 + - _OutlineDistortAmount: 0.5 + - _OutlineDistortTexXSpeed: 5 + - _OutlineDistortTexYSpeed: 5 + - _OutlineDistortToggle: 0 + - _OutlineGlow: 1.5 + - _OutlineIsPixel: 0 + - _OutlinePixelWidth: 1 + - _OutlineTexGrey: 0 + - _OutlineTexToggle: 0 + - _OutlineTexXSpeed: 10 + - _OutlineTexYSpeed: 0 + - _OutlineWidth: 0.004 + - _PinchUvAmount: 0.35 + - _PixelateSize: 32 + - _PosterizeGamma: 0.75 + - _PosterizeNumColors: 8 + - _PosterizeOutline: 0 + - _RectSize: 1 + - _RotateUvAmount: 0 + - _ShadowAlpha: 0.5 + - _ShadowX: 0.1 + - _ShadowY: -0.05 + - _ShakeUvSpeed: 2.5 + - _ShakeUvX: 1.5 + - _ShakeUvY: 1 + - _TextureScrollXSpeed: 1 + - _TextureScrollYSpeed: 0 + - _TwistUvAmount: 1 + - _TwistUvPosX: 0.5 + - _TwistUvPosY: 0.5 + - _TwistUvRadius: 0.75 + - _WaveAmount: 7 + - _WaveSpeed: 10 + - _WaveStrength: 7.5 + - _WaveX: 0 + - _WaveY: 0.5 + - _ZoomUvAmount: 0.5 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _ColorChangeNewCol: {r: 1, g: 1, b: 0, a: 1} + - _ColorChangeTarget: {r: 1, g: 0, b: 0, a: 1} + - _ColorSwapBlue: {r: 1, g: 1, b: 1, a: 1} + - _ColorSwapGreen: {r: 1, g: 1, b: 1, a: 1} + - _ColorSwapRed: {r: 1, g: 1, b: 1, a: 1} + - _FadeBurnColor: {r: 1, g: 1, b: 0, a: 1} + - _GlowColor: {r: 1, g: 1, b: 1, a: 1} + - _GradBotLeftCol: {r: 0, g: 0, b: 1, a: 1} + - _GradBotRightCol: {r: 0, g: 0, b: 1, a: 1} + - _GradTopLeftCol: {r: 1, g: 0, b: 0, a: 1} + - _GradTopRightCol: {r: 1, g: 0, b: 0, a: 1} + - _GreyscaleTintColor: {r: 1, g: 1, b: 1, a: 1} + - _HitEffectColor: {r: 1, g: 1, b: 1, a: 1} + - _InnerOutlineColor: {r: 1, g: 0, b: 0, a: 1} + - _OutlineColor: {r: 1, g: 1, b: 1, a: 1} + - _ShadowColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/Plugins/AllIn1SpriteShader/Materials/EmptyMaterial.mat.meta b/Assets/Plugins/AllIn1SpriteShader/Materials/EmptyMaterial.mat.meta new file mode 100644 index 0000000..a5158ff --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Materials/EmptyMaterial.mat.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: cc460e5b1c6c0bd498b44195a0c3da99 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Materials/EmptyMaterial.mat + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Materials/ScaledTIme.mat b/Assets/Plugins/AllIn1SpriteShader/Materials/ScaledTIme.mat new file mode 100644 index 0000000..5698c93 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Materials/ScaledTIme.mat @@ -0,0 +1,210 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: ScaledTIme + m_Shader: {fileID: 4800000, guid: f3622b3ac1631ea409b0f5811034f3a9, type: 3} + m_ShaderKeywords: ETC1_EXTERNAL_ALPHA + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _ColorRampTex: + m_Texture: {fileID: 2800000, guid: 279657edc397ece4b8029c727adf6ddc, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ColorSwapTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DistortTex: + m_Texture: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _FadeBurnTex: + m_Texture: {fileID: 2800000, guid: 677cca399782dea41aedc1d292ecb67d, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _FadeTex: + m_Texture: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _GlowTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OutlineDistortTex: + m_Texture: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OutlineTex: + m_Texture: {fileID: 2800000, guid: 74087f6d03f233e4a8a142fa01f9e5cf, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ShineMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _Alpha: 1 + - _AlphaCutoffValue: 0.25 + - _AlphaRoundThreshold: 0.5 + - _BillboardY: 0 + - _BlurHD: 0 + - _BlurIntensity: 10 + - _ChromAberrAlpha: 0.4 + - _ChromAberrAmount: 1 + - _ClipUvDown: 1 + - _ClipUvLeft: 1 + - _ClipUvRight: 1 + - _ClipUvUp: 1 + - _ColorChangeLuminosity: 0 + - _ColorChangeTolerance: 0.25 + - _ColorRampLuminosity: 0 + - _ColorRampOutline: 0 + - _ColorSwapBlueLuminosity: 0.5 + - _ColorSwapGreenLuminosity: 0.5 + - _ColorSwapRedLuminosity: 0.5 + - _DistortAmount: 0.5 + - _DistortTexXSpeed: 5 + - _DistortTexYSpeed: 5 + - _FadeAmount: -0.1 + - _FadeBurnGlow: 2 + - _FadeBurnTransition: 0.075 + - _FadeBurnWidth: 0.025 + - _FishEyeUvAmount: 0.35 + - _FlickerAlpha: 0 + - _FlickerFreq: 0.2 + - _FlickerPercent: 0.05 + - _GhostColorBoost: 1 + - _GhostTransparency: 0 + - _GlitchAmount: 3 + - _GlitchSize: 1 + - _Glow: 0 + - _GlowTexUsed: 0 + - _GradBlend: 1 + - _GradBoostX: 1.2 + - _GradBoostY: 1.2 + - _GradIsRadial: 0 + - _GrassManualAnim: 1 + - _GrassManualToggle: 0 + - _GrassSpeed: 2 + - _GrassWind: 20 + - _GreyscaleLuminosity: 0 + - _GreyscaleOutline: 0 + - _HandDrawnAmount: 10 + - _HandDrawnSpeed: 5 + - _HitEffectBlend: 1 + - _HitEffectGlow: 5 + - _HologramFlickerAlpha: 0 + - _HologramFlickerFreq: 0.2 + - _HologramFlickerPercent: 0.05 + - _HologramMaxAlpha: 1 + - _HologramMinAlpha: 0 + - _HologramStripesAlpha: 0.4 + - _HologramStripesAmount: 50 + - _HologramStripesFill: 0.4 + - _HologramStripesLuminosity: 1 + - _HologramStripesSpeed: 5 + - _HologramUnmodAmount: 0.4 + - _HsvBright: 1 + - _HsvSaturation: 1 + - _HsvShift: 180 + - _InnerOutlineAlpha: 1 + - _InnerOutlineGlow: 1 + - _InnerOutlineThickness: 1 + - _MaxXUV: 1 + - _MaxYUV: 1 + - _MinXUV: 0 + - _MinYUV: 0 + - _MotionBlurAngle: 0.1 + - _MotionBlurDist: 1.25 + - _MyDstMode: 10 + - _MySrcMode: 5 + - _NegativeAmount: 1 + - _OffsetUvX: 0 + - _OffsetUvY: 0 + - _OnlyInnerOutline: 0 + - _OnlyOutline: 0 + - _Outline8Directions: 0 + - _OutlineAlpha: 1 + - _OutlineDistortAmount: 0.5 + - _OutlineDistortTexXSpeed: 5 + - _OutlineDistortTexYSpeed: 5 + - _OutlineDistortToggle: 0 + - _OutlineGlow: 1.5 + - _OutlineIsPixel: 0 + - _OutlinePixelWidth: 1 + - _OutlineTexGrey: 0 + - _OutlineTexToggle: 0 + - _OutlineTexXSpeed: 10 + - _OutlineTexYSpeed: 0 + - _OutlineWidth: 0.004 + - _PinchUvAmount: 0.35 + - _PixelateSize: 32 + - _PosterizeGamma: 0.75 + - _PosterizeNumColors: 8 + - _PosterizeOutline: 0 + - _RandomSeed: 0 + - _RectSize: 1 + - _RotateUvAmount: 0 + - _RoundWaveSpeed: 2 + - _RoundWaveStrength: 0.7 + - _ShadowAlpha: 0.5 + - _ShadowX: 0.1 + - _ShadowY: -0.05 + - _ShakeUvSpeed: 2.5 + - _ShakeUvX: 1.5 + - _ShakeUvY: 1 + - _ShineGlow: 1 + - _ShineLocation: 0.5 + - _ShineRotate: 0 + - _ShineWidth: 0.1 + - _TextureScrollXSpeed: 1 + - _TextureScrollYSpeed: 0 + - _TwistUvAmount: 1 + - _TwistUvPosX: 0.5 + - _TwistUvPosY: 0.5 + - _TwistUvRadius: 0.75 + - _WaveAmount: 7 + - _WaveSpeed: 10 + - _WaveStrength: 7.5 + - _WaveX: 0 + - _WaveY: 0.5 + - _ZTestMode: 4 + - _ZWrite: 0 + - _ZoomUvAmount: 0.5 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _ColorChangeNewCol: {r: 1, g: 1, b: 0, a: 1} + - _ColorChangeTarget: {r: 1, g: 0, b: 0, a: 1} + - _ColorSwapBlue: {r: 1, g: 1, b: 1, a: 1} + - _ColorSwapGreen: {r: 1, g: 1, b: 1, a: 1} + - _ColorSwapRed: {r: 1, g: 1, b: 1, a: 1} + - _FadeBurnColor: {r: 1, g: 1, b: 0, a: 1} + - _GlowColor: {r: 1, g: 1, b: 1, a: 1} + - _GradBotLeftCol: {r: 0, g: 0, b: 1, a: 1} + - _GradBotRightCol: {r: 0, g: 0, b: 1, a: 1} + - _GradTopLeftCol: {r: 1, g: 0, b: 0, a: 1} + - _GradTopRightCol: {r: 1, g: 0, b: 0, a: 1} + - _GreyscaleTintColor: {r: 1, g: 1, b: 1, a: 1} + - _HitEffectColor: {r: 1, g: 1, b: 1, a: 1} + - _HologramStripeColor: {r: 0, g: 1, b: 1, a: 1} + - _InnerOutlineColor: {r: 1, g: 0, b: 0, a: 1} + - _OutlineColor: {r: 1, g: 1, b: 1, a: 1} + - _ShadowColor: {r: 0, g: 0, b: 0, a: 1} + - _ShineColor: {r: 1, g: 1, b: 1, a: 1} diff --git a/Assets/Plugins/AllIn1SpriteShader/Materials/ScaledTIme.mat.meta b/Assets/Plugins/AllIn1SpriteShader/Materials/ScaledTIme.mat.meta new file mode 100644 index 0000000..6b906f8 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Materials/ScaledTIme.mat.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 3241ea466d4f8334898daf420de4026b +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Materials/ScaledTIme.mat + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Materials/UIStencil.mat b/Assets/Plugins/AllIn1SpriteShader/Materials/UIStencil.mat new file mode 100644 index 0000000..bf67988 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Materials/UIStencil.mat @@ -0,0 +1,177 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: UIStencil + m_Shader: {fileID: 4800000, guid: a53f4bb29f3644b43b5075c6dcfecb32, type: 3} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _ColorRampTex: + m_Texture: {fileID: 2800000, guid: 279657edc397ece4b8029c727adf6ddc, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ColorSwapTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DistortTex: + m_Texture: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _FadeBurnTex: + m_Texture: {fileID: 2800000, guid: 677cca399782dea41aedc1d292ecb67d, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _FadeTex: + m_Texture: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _GlowTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OutlineDistortTex: + m_Texture: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OutlineTex: + m_Texture: {fileID: 2800000, guid: 74087f6d03f233e4a8a142fa01f9e5cf, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _Alpha: 1 + - _AlphaCutoffValue: 0.25 + - _BlurHD: 0 + - _BlurIntensity: 10 + - _ChromAberrAlpha: 0.4 + - _ChromAberrAmount: 1 + - _ClipUvDown: 0 + - _ClipUvLeft: 0 + - _ClipUvRight: 0 + - _ClipUvUp: 0 + - _ColorChangeLuminosity: 0 + - _ColorChangeTolerance: 0.25 + - _ColorRampLuminosity: 0 + - _ColorRampOutline: 0 + - _ColorSwapBlueLuminosity: 0.5 + - _ColorSwapGreenLuminosity: 0.5 + - _ColorSwapRedLuminosity: 0.5 + - _DistortAmount: 0.5 + - _DistortTexXSpeed: 5 + - _DistortTexYSpeed: 5 + - _FadeAmount: -0.1 + - _FadeBurnGlow: 2 + - _FadeBurnTransition: 0.075 + - _FadeBurnWidth: 0.025 + - _FishEyeUvAmount: 0.35 + - _FlickerAlpha: 0 + - _FlickerFreq: 0.2 + - _FlickerPercent: 0.05 + - _GhostColorBoost: 1 + - _GhostTransparency: 0 + - _GlitchAmount: 3 + - _Glow: 10 + - _GlowTexUsed: 0 + - _GradBlend: 1 + - _GrassManualAnim: 1 + - _GrassManualToggle: 0 + - _GrassSpeed: 2 + - _GrassWind: 20 + - _GreyscaleLuminosity: 0 + - _GreyscaleOutline: 0 + - _HandDrawnAmount: 10 + - _HandDrawnSpeed: 5 + - _HitEffectBlend: 1 + - _HitEffectGlow: 5 + - _HologramFlickerAlpha: 0 + - _HologramFlickerFreq: 0.2 + - _HologramStripesAlpha: 0.4 + - _HologramStripesAmount: 50 + - _HologramStripesFill: 0.4 + - _HologramStripesLuminosity: 1 + - _HologramStripesSpeed: 5 + - _HsvBright: 1 + - _HsvSaturation: 1 + - _HsvShift: 180 + - _InnerOutlineAlpha: 1 + - _InnerOutlineGlow: 1 + - _InnerOutlineThickness: 1 + - _MotionBlurAngle: 0.1 + - _MotionBlurDist: 1.25 + - _NegativeAmount: 1 + - _OffsetUvX: 0 + - _OffsetUvY: 0 + - _Outline8Directions: 0 + - _OutlineAlpha: 1 + - _OutlineDistortAmount: 0.5 + - _OutlineDistortTexXSpeed: 5 + - _OutlineDistortTexYSpeed: 5 + - _OutlineDistortToggle: 0 + - _OutlineGlow: 1.5 + - _OutlineIsPixel: 0 + - _OutlinePixelWidth: 1 + - _OutlineTexGrey: 0 + - _OutlineTexToggle: 0 + - _OutlineTexXSpeed: 10 + - _OutlineTexYSpeed: 0 + - _OutlineWidth: 0.004 + - _PinchUvAmount: 0.35 + - _PixelateSize: 32 + - _PosterizeGamma: 0.75 + - _PosterizeNumColors: 8 + - _PosterizeOutline: 0 + - _RectSize: 1 + - _RotateUvAmount: 0 + - _ShadowAlpha: 0.5 + - _ShadowX: 0.1 + - _ShadowY: -0.05 + - _ShakeUvSpeed: 2.5 + - _ShakeUvX: 1.5 + - _ShakeUvY: 1 + - _TextureScrollXSpeed: 1 + - _TextureScrollYSpeed: 0 + - _TwistUvAmount: 1 + - _TwistUvPosX: 0.5 + - _TwistUvPosY: 0.5 + - _TwistUvRadius: 0.75 + - _WaveAmount: 7 + - _WaveSpeed: 10 + - _WaveStrength: 7.5 + - _WaveX: 0 + - _WaveY: 0.5 + - _ZoomUvAmount: 0.5 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _ColorChangeNewCol: {r: 1, g: 1, b: 0, a: 1} + - _ColorChangeTarget: {r: 1, g: 0, b: 0, a: 1} + - _ColorSwapBlue: {r: 1, g: 1, b: 1, a: 1} + - _ColorSwapGreen: {r: 1, g: 1, b: 1, a: 1} + - _ColorSwapRed: {r: 1, g: 1, b: 1, a: 1} + - _FadeBurnColor: {r: 1, g: 1, b: 0, a: 1} + - _GlowColor: {r: 1, g: 1, b: 1, a: 1} + - _GradBotLeftCol: {r: 0, g: 0, b: 1, a: 1} + - _GradBotRightCol: {r: 0, g: 0, b: 1, a: 1} + - _GradTopLeftCol: {r: 1, g: 0, b: 0, a: 1} + - _GradTopRightCol: {r: 1, g: 0, b: 0, a: 1} + - _GreyscaleTintColor: {r: 1, g: 1, b: 1, a: 1} + - _HitEffectColor: {r: 1, g: 1, b: 1, a: 1} + - _InnerOutlineColor: {r: 1, g: 0, b: 0, a: 1} + - _OutlineColor: {r: 1, g: 1, b: 1, a: 1} + - _ShadowColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/Plugins/AllIn1SpriteShader/Materials/UIStencil.mat.meta b/Assets/Plugins/AllIn1SpriteShader/Materials/UIStencil.mat.meta new file mode 100644 index 0000000..b7bff5b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Materials/UIStencil.mat.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +guid: 7ef34f26b8117334c8ecd9c27a45e2c6 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Materials/UIStencil.mat + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts.meta new file mode 100644 index 0000000..25e7f5c --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4e5ef1ce32696cd4c8ddbe3e0e172819 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/All1CreateUnifiedOutline.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/All1CreateUnifiedOutline.cs new file mode 100644 index 0000000..6ecf90b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/All1CreateUnifiedOutline.cs @@ -0,0 +1,96 @@ +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace AllIn1SpriteShader +{ + [ExecuteInEditMode] + public class All1CreateUnifiedOutline : MonoBehaviour + { + [SerializeField] private Material outlineMaterial = null; + [SerializeField] private Transform outlineParentTransform = null; + + [Space] + [Header("Only needed if Sprite (ignored if UI)")] + [SerializeField] private int duplicateOrderInLayer = -100; + [SerializeField] private string duplicateSortingLayer = "Default"; + + [Space] + [Header("This operation will delete the component")] + [SerializeField] private bool createUnifiedOutline; + + void Update() + { + if (createUnifiedOutline) + { + if (outlineMaterial == null) + { + createUnifiedOutline = false; + MissingMaterial(); + return; + } + + List children = new List(); + GetAllChildren(transform, ref children); + foreach (Transform t in children) CreateOutlineSpriteDuplicate(t.gameObject); + CreateOutlineSpriteDuplicate(gameObject); + + DestroyImmediate(this); + } + } + + private void CreateOutlineSpriteDuplicate(GameObject target) + { + bool objectIsUi = false; + SpriteRenderer ownSr = target.GetComponent(); + Image ownImage = target.GetComponent(); + if (ownSr != null) objectIsUi = false; + else if (ownImage != null) objectIsUi = true; + else if (ownSr == null && ownImage == null && !transform.Equals(outlineParentTransform)) return; + + GameObject objDuplicate = new GameObject(); + objDuplicate.name = target.name + "Outline"; + objDuplicate.transform.position = target.transform.position; + objDuplicate.transform.rotation = target.transform.rotation; + objDuplicate.transform.localScale = target.transform.lossyScale; + if (outlineParentTransform == null) objDuplicate.transform.parent = target.transform; + else objDuplicate.transform.parent = outlineParentTransform; + + if (!objectIsUi) + { + SpriteRenderer sr = objDuplicate.AddComponent(); + sr.sprite = ownSr.sprite; + sr.sortingOrder = duplicateOrderInLayer; + sr.sortingLayerName = duplicateSortingLayer; + sr.material = outlineMaterial; + sr.flipX = ownSr.flipX; + sr.flipY = ownSr.flipY; + } + else + { + Image image = objDuplicate.AddComponent(); + image.sprite = ownImage.sprite; + image.material = outlineMaterial; + } + } + + private void MissingMaterial() + { +#if UNITY_EDITOR + EditorUtility.DisplayDialog("Missing Material", "Please assign a Material For New Duplicate and try again", "Ok"); +#endif + } + + private void GetAllChildren(Transform parent, ref List transforms) + { + foreach (Transform child in parent) + { + transforms.Add(child); + GetAllChildren(child, ref transforms); + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/All1CreateUnifiedOutline.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/All1CreateUnifiedOutline.cs.meta new file mode 100644 index 0000000..c87669b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/All1CreateUnifiedOutline.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 264cca4d0f5bbb54eb9de18ca54d1506 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/All1CreateUnifiedOutline.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1Shader.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1Shader.cs new file mode 100644 index 0000000..240ba1d --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1Shader.cs @@ -0,0 +1,829 @@ +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using UnityEngine; +using UnityEngine.Tilemaps; +using UnityEngine.UI; +#if UNITY_EDITOR +using UnityEditor.SceneManagement; +#endif + +namespace AllIn1SpriteShader +{ + [ExecuteInEditMode] + [DisallowMultipleComponent] + [AddComponentMenu("AllIn1SpriteShader/AddAllIn1Shader")] + public class AllIn1Shader : MonoBehaviour + { + public enum ShaderTypes + { + Default = 0, + ScaledTime = 1, + MaskedUI = 2, + Urp2dRenderer = 3, + Lit = 5, + SRPBatcher = 6, + Invalid = 4, + } + public ShaderTypes currentShaderType = ShaderTypes.Invalid; + + private Material currMaterial, prevMaterial; + private bool destroyed = false; +#if UNITY_EDITOR + private bool matAssigned = false; +#endif + private enum AfterSetAction { Clear, CopyMaterial, Reset}; + + [Range(1f, 20f)] public float normalStrength = 5f; + [Range(0f, 3f)] public int normalSmoothing = 1; + [HideInInspector] public bool computingNormal = false; + +#if UNITY_EDITOR + private static float timeLastReload = -1f; + private void Start() + { + if(timeLastReload < 0) timeLastReload = Time.time; + } + + private void Update() + { + if (matAssigned || Application.isPlaying || !gameObject.activeSelf) return; + Renderer sr = GetComponent(); + if (sr != null) + { + if (sr.sharedMaterial == null) + { + CleanMaterial(); + MakeNewMaterial(true); + } + if (sr.sharedMaterial.name.Contains("Default")) MakeNewMaterial(true); + else matAssigned = true; + } + else + { + Graphic img = GetComponent(); + if (img != null) + { + if (img.material.name.Contains("Default")) MakeNewMaterial(true); + else matAssigned = true; + } + } + } +#endif + + private void MakeNewMaterial(bool getShaderTypeFromPrefs, string shaderName = "AllIn1SpriteShader") + { + bool operationSuccessful = SetMaterial(AfterSetAction.Clear, getShaderTypeFromPrefs, shaderName); + #if UNITY_EDITOR + if(operationSuccessful) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Material Created and Assigned"); + #endif + } + + public bool MakeCopy() + { + return SetMaterial(AfterSetAction.CopyMaterial, false, GetStringFromShaderType()); + } + + private void ResetAllProperties(bool getShaderTypeFromPrefs, string shaderName) + { + SetMaterial(AfterSetAction.Reset, getShaderTypeFromPrefs, shaderName); + } + + private string GetStringFromShaderType() + { + currentShaderType = ShaderTypes.Default; + if (currentShaderType == ShaderTypes.Default) return "AllIn1SpriteShader"; + else if (currentShaderType == ShaderTypes.ScaledTime) return "AllIn1SpriteShaderScaledTime"; + else if (currentShaderType == ShaderTypes.MaskedUI) return "AllIn1SpriteShaderUiMask"; + else if (currentShaderType == ShaderTypes.Urp2dRenderer) return "AllIn1Urp2dRenderer"; + else if (currentShaderType == ShaderTypes.Lit) return "AllIn1SpriteShaderLit"; + else if (currentShaderType == ShaderTypes.SRPBatcher) return "AllIn1SpriteShaderSRPBatch"; + + else return "AllIn1SpriteShader"; + } + + private bool SetMaterial(AfterSetAction action, bool getShaderTypeFromPrefs, string shaderName) + { + #if UNITY_EDITOR + Shader allIn1Shader = AllIn1ShaderWindow.FindShader(shaderName); + if (getShaderTypeFromPrefs) + { + int shaderVariant = PlayerPrefs.GetInt("allIn1DefaultShader"); + currentShaderType = (ShaderTypes)shaderVariant; + if (shaderVariant == 1) allIn1Shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderScaledTime"); + else if (shaderVariant == 2) allIn1Shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderUiMask"); + else if (shaderVariant == 3) allIn1Shader = AllIn1ShaderWindow.FindShader("AllIn1Urp2dRenderer"); + else if (shaderVariant == 5) allIn1Shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderLit"); + else if (shaderVariant == 6) allIn1Shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderSRPBatch"); + } + + if (!Application.isPlaying && Application.isEditor && allIn1Shader != null) + { + bool rendererExists = false; + Renderer sr = GetComponent(); + if (sr != null) + { + rendererExists = true; + int renderingQueue = 3000; + if(action == AfterSetAction.CopyMaterial) renderingQueue = GetComponent().sharedMaterial.renderQueue; + prevMaterial = new Material(GetComponent().sharedMaterial); + currMaterial = new Material(allIn1Shader); + currMaterial.renderQueue = renderingQueue; + GetComponent().sharedMaterial = currMaterial; + GetComponent().sharedMaterial.hideFlags = HideFlags.None; + matAssigned = true; + + DoAfterSetAction(action); + } + else + { + Graphic img = GetComponent(); + if (img != null) + { + rendererExists = true; + int renderingQueue = 3000; + if(action == AfterSetAction.CopyMaterial) renderingQueue = img.material.renderQueue; + prevMaterial = new Material(img.material); + currMaterial = new Material(allIn1Shader); + currMaterial.renderQueue = renderingQueue; + img.material = currMaterial; + img.material.hideFlags = HideFlags.None; + matAssigned = true; + DoAfterSetAction(action); + } + } + if (!rendererExists) + { + MissingRenderer(); + return false; + } + else + { + SetSceneDirty(); + return true; + } + } + else if (allIn1Shader == null) + { + #if UNITY_EDITOR + string logErrorMessage = "Make sure all AllIn1SpriteShader shader variants are present. Maybe delete the asset and download it again?"; + Debug.LogError(logErrorMessage); + AllIn1ShaderWindow.ShowSceneViewNotification(logErrorMessage); + #endif + return false; + } + #endif + return false; + } + + private void DoAfterSetAction(AfterSetAction action) + { + switch (action) + { + case AfterSetAction.Clear: + ClearAllKeywords(); + break; + case AfterSetAction.CopyMaterial: + currMaterial.CopyPropertiesFromMaterial(prevMaterial); + break; + } + } + + public bool TryCreateNew() + { + bool rendererExists = false; + Renderer sr = GetComponent(); + if (sr != null) + { + rendererExists = true; + if (sr != null && sr.sharedMaterial != null && sr.sharedMaterial.name.Contains("AllIn1")) + { + ResetAllProperties(false, GetStringFromShaderType()); + ClearAllKeywords(); + } + else + { + CleanMaterial(); + MakeNewMaterial(false, GetStringFromShaderType()); + } + } + else + { + Graphic img = GetComponent(); + if (img != null) + { + rendererExists = true; + if (img.material.name.Contains("AllIn1")) + { + ResetAllProperties(false, GetStringFromShaderType()); + ClearAllKeywords(); + } + else MakeNewMaterial(false, GetStringFromShaderType()); + } + } + if (!rendererExists) + { + MissingRenderer(); + } + SetSceneDirty(); + return rendererExists; + } + + public void ClearAllKeywords() + { + SetKeyword("RECTSIZE_ON"); + SetKeyword("OFFSETUV_ON"); + SetKeyword("CLIPPING_ON"); + SetKeyword("POLARUV_ON"); + SetKeyword("TWISTUV_ON"); + SetKeyword("ROTATEUV_ON"); + SetKeyword("FISHEYE_ON"); + SetKeyword("PINCH_ON"); + SetKeyword("SHAKEUV_ON"); + SetKeyword("WAVEUV_ON"); + SetKeyword("ROUNDWAVEUV_ON"); + SetKeyword("DOODLE_ON"); + SetKeyword("ZOOMUV_ON"); + SetKeyword("FADE_ON"); + SetKeyword("TEXTURESCROLL_ON"); + SetKeyword("GLOW_ON"); + SetKeyword("OUTBASE_ON"); + SetKeyword("ONLYOUTLINE_ON"); + SetKeyword("OUTTEX_ON"); + SetKeyword("OUTDIST_ON"); + SetKeyword("DISTORT_ON"); + SetKeyword("WIND_ON"); + SetKeyword("GRADIENT_ON"); + SetKeyword("GRADIENT2COL_ON"); + SetKeyword("RADIALGRADIENT_ON"); + SetKeyword("COLORSWAP_ON"); + SetKeyword("HSV_ON"); + SetKeyword("HITEFFECT_ON"); + SetKeyword("PIXELATE_ON"); + SetKeyword("NEGATIVE_ON"); + SetKeyword("GRADIENTCOLORRAMP_ON"); + SetKeyword("COLORRAMP_ON"); + SetKeyword("GREYSCALE_ON"); + SetKeyword("POSTERIZE_ON"); + SetKeyword("BLUR_ON"); + SetKeyword("MOTIONBLUR_ON"); + SetKeyword("GHOST_ON"); + SetKeyword("ALPHAOUTLINE_ON"); + SetKeyword("INNEROUTLINE_ON"); + SetKeyword("ONLYINNEROUTLINE_ON"); + SetKeyword("HOLOGRAM_ON"); + SetKeyword("CHROMABERR_ON"); + SetKeyword("GLITCH_ON"); + SetKeyword("FLICKER_ON"); + SetKeyword("SHADOW_ON"); + SetKeyword("SHINE_ON"); + SetKeyword("CONTRAST_ON"); + SetKeyword("OVERLAY_ON"); + SetKeyword("OVERLAYMULT_ON"); + SetKeyword("ALPHACUTOFF_ON"); + SetKeyword("ALPHAROUND_ON"); + SetKeyword("CHANGECOLOR_ON"); + SetKeyword("CHANGECOLOR2_ON"); + SetKeyword("CHANGECOLOR3_ON"); + SetKeyword("FOG_ON"); + SetSceneDirty(); + } + + private void SetKeyword(string keyword, bool state = false) + { + if (destroyed) return; + if (currMaterial == null) + { + FindCurrMaterial(); + if (currMaterial == null) + { + MissingRenderer(); + return; + } + } + if (!state) currMaterial.DisableKeyword(keyword); + else currMaterial.EnableKeyword(keyword); + } + + private void FindCurrMaterial() + { + Renderer sr = GetComponent(); + if (sr != null) + { + currMaterial = GetComponent().sharedMaterial; +#if UNITY_EDITOR + matAssigned = true; +#endif + } + else + { + Graphic img = GetComponent(); + if (img != null) + { + currMaterial = img.material; +#if UNITY_EDITOR + matAssigned = true; +#endif + } + } + } + + public void CleanMaterial() + { + Renderer sr = GetComponent(); + if (sr != null) + { + sr.sharedMaterial = new Material(Shader.Find("Sprites/Default")); +#if UNITY_EDITOR + matAssigned = false; +#endif + } + else + { + Graphic img = GetComponent(); + if (img != null) + { + img.material = new Material(Shader.Find("Sprites/Default")); +#if UNITY_EDITOR + matAssigned = false; +#endif + } + } + SetSceneDirty(); + } + + public bool SaveMaterial() + { +#if UNITY_EDITOR + string sameMaterialPath = AllIn1ShaderWindow.GetMaterialSavePath(); + sameMaterialPath += "/"; + if (!System.IO.Directory.Exists(sameMaterialPath)) + { + EditorUtility.DisplayDialog("The desired Material Save Path doesn't exist", + "Go to Window -> AllIn1ShaderWindow and set a valid folder", "Ok"); + return false; + } + sameMaterialPath += gameObject.name; + string fullPath = sameMaterialPath + ".mat"; + if (System.IO.File.Exists(fullPath)) + { + SaveMaterialWithOtherName(sameMaterialPath); + } + else DoSaving(fullPath); + SetSceneDirty(); + return true; +#else + return false; +#endif + } + private void SaveMaterialWithOtherName(string path, int i = 1) + { + int number = i; + string newPath = path + "_" + number.ToString(); + string fullPath = newPath + ".mat"; + if (System.IO.File.Exists(fullPath)) + { + number++; + SaveMaterialWithOtherName(path, number); + } + else + { + DoSaving(fullPath); + } + } + + private void DoSaving(string fileName) + { +#if UNITY_EDITOR + bool rendererExists = false; + Renderer sr = GetComponent(); + Material matToSave = null; + Material createdMat = null; + if (sr != null) + { + rendererExists = true; + matToSave = sr.sharedMaterial; + } + else + { + Graphic img = GetComponent(); + if (img != null) + { + rendererExists = true; + matToSave = img.material; + } + } + if (!rendererExists) + { + MissingRenderer(); + return; + } + else + { + createdMat = new Material(matToSave); + currMaterial = createdMat; + AssetDatabase.CreateAsset(createdMat, fileName); + Debug.Log(fileName + " has been saved!"); + EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(fileName, typeof(Material))); + } + if (sr != null) + { + sr.material = createdMat; + } + else + { + Graphic img = GetComponent(); + img.material = createdMat; + } +#endif + } + + public void SetSceneDirty() + { +#if UNITY_EDITOR + if (!Application.isPlaying) EditorSceneManager.MarkAllScenesDirty(); + + //If you get an error here please delete the code block below + #if UNITY_2021_2_OR_NEWER + var prefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); + #else + var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); + #endif + if (prefabStage != null) EditorSceneManager.MarkSceneDirty(prefabStage.scene); + //Until here +#endif + } + + private void MissingRenderer() + { +#if UNITY_EDITOR + EditorUtility.DisplayDialog("Missing Renderer", "This GameObject (" + + gameObject.name + ") has no Renderer or UI Image component. This AllIn1Shader component will be removed.", "Ok"); + destroyed = true; + DestroyImmediate(this); +#endif + } + + public bool ToggleSetAtlasUvs(bool activate) + { + bool success = false; + SetAtlasUvs atlasUvs = GetComponent(); + if (activate) + { + if (atlasUvs == null) atlasUvs = gameObject.AddComponent(); + if (atlasUvs != null) success = atlasUvs.GetAndSetUVs(); + if(success) SetKeyword("ATLAS_ON", true); + } + else + { + if (atlasUvs != null) + { + atlasUvs.ResetAtlasUvs(); + DestroyImmediate(atlasUvs); + success = true; + } + else + { + #if UNITY_EDITOR + EditorUtility.DisplayDialog("Missing Atlas Uv Setup", "This GameObject (" + gameObject.name + ") has no Atlas Uv Setup.", "Ok"); + #endif + return false; + } + SetKeyword("ATLAS_ON", false); + } + SetSceneDirty(); + return success; + } + + public bool ApplyMaterialToHierarchy() + { + Renderer sr = GetComponent(); + Graphic image = GetComponent(); + Material matToApply = null; + if (sr != null) matToApply = sr.sharedMaterial; + else if (image != null) + { + matToApply = image.material; + } + else + { + MissingRenderer(); + return false; + } + + List children = new List(); + GetAllChildren(transform, ref children); + bool hasPerformedOperation = false; + foreach (Transform t in children) + { + sr = t.gameObject.GetComponent(); + if (sr != null) sr.material = matToApply; + else + { + image = t.gameObject.GetComponent(); + if (image != null) image.material = matToApply; + } + hasPerformedOperation = true; + } + + return hasPerformedOperation; + } + + public void CheckIfValidTarget() + { + Renderer sr = GetComponent(); + Graphic image = GetComponent(); + if (sr == null && image == null) MissingRenderer(); + } + + private void GetAllChildren(Transform parent, ref List transforms) + { + foreach (Transform child in parent) + { + transforms.Add(child); + GetAllChildren(child, ref transforms); + } + } + + public bool RenderToImage() + { +#if UNITY_EDITOR + if (currMaterial == null) + { + FindCurrMaterial(); + if (currMaterial == null) + { + MissingRenderer(); + return false; + } + } + Texture tex = currMaterial.GetTexture("_MainTex"); + if(tex != null) + { + bool success = RenderAndSaveTexture(currMaterial, tex); + if(!success) return false; + } + else + { + SpriteRenderer sr = GetComponent(); + Graphic i = GetComponent(); + if (sr != null && sr.sprite != null && sr.sprite.texture != null) tex = sr.sprite.texture; + else if (i != null && i.mainTexture != null) tex = i.mainTexture; + + if(tex != null) + { + bool success = RenderAndSaveTexture(currMaterial, tex); + if(!success) return false; + } + else{ + EditorUtility.DisplayDialog("No valid target texture found", "All In 1 Shader component couldn't find a valid Main Texture in this GameObject (" + + gameObject.name + "). This means that the material you are using has no Main Texture or that the texture couldn't be reached through the Renderer component you are using." + + " Please make sure to have a valid Main Texture in the Material or Renderer/Graphic component", "Ok"); + return false; + } + } + return true; +#else + return false; +#endif + } + + private bool RenderAndSaveTexture(Material targetMaterial, Texture targetTexture) + { +#if UNITY_EDITOR + float scaleSlider = 1; + if (PlayerPrefs.HasKey("All1ShaderRenderImagesScale")) scaleSlider = PlayerPrefs.GetFloat("All1ShaderRenderImagesScale"); + RenderTexture renderTarget = new RenderTexture((int)(targetTexture.width * scaleSlider), (int)(targetTexture.height * scaleSlider), 0, RenderTextureFormat.ARGB32); + Graphics.Blit(targetTexture, renderTarget, targetMaterial); + Texture2D reaultTex = new Texture2D(renderTarget.width, renderTarget.height, TextureFormat.ARGB32, false); + reaultTex.ReadPixels(new Rect(0, 0, renderTarget.width, renderTarget.height), 0, 0); + reaultTex.Apply(); + + string path = AllIn1ShaderWindow.GetRenderImageSavePath(); + path += "/"; + if (!System.IO.Directory.Exists(path)) + { + EditorUtility.DisplayDialog("The desired Material to Image Save Path doesn't exist", + "Go to Window -> AllIn1ShaderWindow and set a valid folder", "Ok"); + return false; + } + string fullPath = path + gameObject.name + ".png"; + if (System.IO.File.Exists(fullPath)) fullPath = GetNewValidPath(path + gameObject.name); + string pingPath = fullPath; + + string fileName = fullPath.Replace(path, ""); + fileName = fileName.Replace(".png", ""); + fullPath = EditorUtility.SaveFilePanel("Save Render Image", path, fileName, "png"); + if(string.IsNullOrEmpty(fullPath)) + { + Debug.Log("Save operation was cancelled or no valid path was selected."); + return false; + } + + byte[] bytes = reaultTex.EncodeToPNG(); + File.WriteAllBytes(fullPath, bytes); + AssetDatabase.ImportAsset(subPath); + AssetDatabase.Refresh(); + DestroyImmediate(reaultTex); + EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(pingPath, typeof(Texture))); + Debug.Log("Render Image saved to: " + fullPath + " with scale: " + scaleSlider + " (it can be changed in Window -> AllIn1ShaderWindow)"); + return true; +#else + return false; +#endif + + } + + private string GetNewValidPath(string path, int i = 1) + { + int number = i; + string newPath = path + "_" + number.ToString(); + string fullPath = newPath + ".png"; + if (System.IO.File.Exists(fullPath)) + { + number++; + fullPath = GetNewValidPath(path, number); + } + return fullPath; + } + + #region normalMapCreator + protected virtual void OnEnable() + { +#if UNITY_EDITOR + EditorApplication.update += OnEditorUpdate; +#endif + } + + protected virtual void OnDisable() + { +#if UNITY_EDITOR + EditorApplication.update -= OnEditorUpdate; +#endif + } + + bool needToWait; + int waitingCycles; + int timesWeWaited; + protected virtual void OnEditorUpdate() + { + if (computingNormal) + { + if (needToWait) + { + waitingCycles++; + if (waitingCycles > 5) + { + needToWait = false; + timesWeWaited++; + } + } + else + { + if (timesWeWaited == 1) SetNewNormalTexture2(); + if (timesWeWaited == 2) SetNewNormalTexture3(); + if (timesWeWaited == 3) SetNewNormalTexture4(); + needToWait = true; + } + } + } + + SpriteRenderer normalMapSr; + Renderer normalMapRenderer; + bool isSpriteRenderer; + public void CreateAndAssignNormalMap() + { +#if UNITY_EDITOR + if (GetComponent() != null) + { + EditorUtility.DisplayDialog("This is a tilemap", "This feature isn't supported on Tilemap Renderers." + + " Add a secondary normal map texture instead (you can create a Normal Map in the asset Window)", "Ok"); + return; + } + + normalMapSr = GetComponent(); + normalMapRenderer = GetComponent(); + //Debug.LogError($"NORMALMAP_ON: {normalMapRenderer.sharedMaterial.IsKeywordEnabled("NORMALMAP_ON")} -t:{Time.time}"); + if (normalMapSr != null) + { + isSpriteRenderer = true; + SetNewNormalTexture(); + if(!normalMapSr.sharedMaterial.IsKeywordEnabled("NORMALMAP_ON")) normalMapSr.sharedMaterial.EnableKeyword("NORMALMAP_ON"); + } + else if (normalMapRenderer != null) + { + isSpriteRenderer = false; + SetNewNormalTexture(); + if(!normalMapRenderer.sharedMaterial.IsKeywordEnabled("NORMALMAP_ON")) normalMapRenderer.sharedMaterial.EnableKeyword("NORMALMAP_ON"); + } + else + { + if (GetComponent() != null) + { + EditorUtility.DisplayDialog("This is a UI element", "This GameObject (" + + gameObject.name + ") is a UI element. UI elements probably shouldn't have a normal map. Why are you using the light shader variant?", "Ok"); + } + else + { + MissingRenderer(); + } + return; + } +#endif + } + + string path; + private void SetNewNormalTexture() + { +#if UNITY_EDITOR + path = AllIn1ShaderWindow.GetNormalMapSavePath(); + path += "/"; + if (!System.IO.Directory.Exists(path)) + { + EditorUtility.DisplayDialog("The desired folder doesn't exist", + "Go to Window -> AllIn1ShaderWindow and set a valid folder", "Ok"); + return; + } + + computingNormal = true; + needToWait = true; + waitingCycles = 0; + timesWeWaited = 0; +#else + computingNormal = false; + return; +#endif + } + +#if UNITY_EDITOR + TextureImporter importer; + Texture2D mainTex2D; +#endif + private void SetNewNormalTexture2() + { +#if UNITY_EDITOR + if (!isSpriteRenderer) + { + mainTex2D = (Texture2D)normalMapRenderer.sharedMaterial.GetTexture("_MainTex"); + importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(mainTex2D)) as TextureImporter; + } + else importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(normalMapSr.sprite)) as TextureImporter; + + importer.isReadable = true; + importer.SaveAndReimport(); +#endif + } + + string subPath; + private void SetNewNormalTexture3() + { +#if UNITY_EDITOR + Texture2D normalM = null; + if(isSpriteRenderer) normalM = AllIn1ShaderWindow.CreateNormalMap(normalMapSr.sprite.texture, normalStrength, normalSmoothing); + else normalM = AllIn1ShaderWindow.CreateNormalMap(mainTex2D, normalStrength, normalSmoothing); + + byte[] bytes = normalM.EncodeToPNG(); + + path += gameObject.name; + subPath = path + ".png"; + string dataPath = Application.dataPath; + dataPath = dataPath.Replace("/Assets", "/"); + string fullPath = dataPath + subPath; + + File.WriteAllBytes(fullPath, bytes); + AssetDatabase.ImportAsset(subPath); + AssetDatabase.Refresh(); + DestroyImmediate(normalM); +#endif + } + + private void SetNewNormalTexture4() + { +#if UNITY_EDITOR + importer = AssetImporter.GetAtPath(subPath) as TextureImporter; + importer.filterMode = FilterMode.Bilinear; + importer.textureType = TextureImporterType.NormalMap; + importer.wrapMode = TextureWrapMode.Repeat; + importer.SaveAndReimport(); + + if (currMaterial == null) + { + FindCurrMaterial(); + if (currMaterial == null) + { + MissingRenderer(); + return; + } + } + Texture2D normalTex = (Texture2D)AssetDatabase.LoadAssetAtPath(subPath, typeof(Texture2D)); + currMaterial.SetTexture("_NormalMap", normalTex); + + Debug.Log("Normal texture saved to: " + subPath); + EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(subPath, typeof(Texture))); + + computingNormal = false; +#endif + } + #endregion + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1Shader.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1Shader.cs.meta new file mode 100644 index 0000000..6baa8aa --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1Shader.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: ee158225ee1e59f4791627785501d950 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1Shader.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs new file mode 100644 index 0000000..9383ae9 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs @@ -0,0 +1,695 @@ +#if UNITY_EDITOR +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn1SpriteShader +{ + public class AllIn1ShaderWindow : EditorWindow + { + private const string versionString = "4.661"; + [MenuItem("Tools/AllIn1/SpriteShaderWindow")] + public static void ShowAllIn1ShaderWindowWindow() + { + GetWindow("All In 1 Shader Window"); + } + + public static readonly string CUSTOM_EDITOR_HEADER = "AllIn1SpriteShaderEditorImage"; + private static string basePath = "Assets/Plugins/AllIn1SpriteShader"; + public static readonly string materialsSavesRelativePath = "/Materials"; + public static readonly string renderImagesSavesRelativePath = "/Textures"; + public static readonly string normalMapSavesRelativePath = "/Textures/NormalMaps"; + public static readonly string gradientSavesRelativePath = "/Textures/GradientTextures"; + + public Vector2 scrollPosition = Vector2.zero; + private Texture2D imageInspector; + private DefaultAsset materialTargetFolder = null; + private GUIStyle style, bigLabel = new GUIStyle(), titleStyle = new GUIStyle(); + private const int bigFontSize = 16; + + AllIn1Shader.ShaderTypes shaderTypes = AllIn1Shader.ShaderTypes.Default; + bool showUrpWarning = false; + double warningTime = 0f; + + private Texture2D targetNormalImage; + private float normalStrength = 5f; + private int normalSmoothing = 1; + private int isComputingNormals = 0; + + private enum TextureSizes + { + _2 = 2, + _4 = 4, + _8 = 8, + _16 = 16, + _32 = 32, + _64 = 64, + _128 = 128, + _256 = 256, + _512 = 512, + _1024 = 1024, + _2048 = 2048 + } + private TextureSizes textureSizes = TextureSizes._128; + [SerializeField] private Gradient gradient = new Gradient(); + private FilterMode gradientFiltering = FilterMode.Bilinear; + + private enum ImageType + { + ShowImage, + HideInComponent, + HideEverywhere + } + private ImageType imageType; + + private void OnGUI() + { + style = new GUIStyle(EditorStyles.helpBox); + style.margin = new RectOffset(0, 0, 0, 0); + bigLabel = new GUIStyle(EditorStyles.boldLabel); + bigLabel.fontSize = bigFontSize; + titleStyle.alignment = TextAnchor.MiddleLeft; + + using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPosition, GUILayout.Width(position.width), GUILayout.Height(position.height))) + { + scrollPosition = scrollView.scrollPosition; + + ShowImageAndSetImageEditorPref(); + + ShowAssetImageOptionsToggle(); + + DefaultAssetShader(); + + DrawLine(Color.grey, 1, 3); + GUILayout.Label("Material Save Path", bigLabel); + GUILayout.Space(20); + GUILayout.Label("Select the folder where new Materials will be saved when the Save Material To Folder button of the asset component is pressed", EditorStyles.boldLabel); + HandleSaveFolderEditorPref("All1ShaderMaterials", basePath + materialsSavesRelativePath, "Material"); + + DrawLine(Color.grey, 1, 3); + GUILayout.Label("Render Material to Image Save Path", bigLabel); + GUILayout.Space(20); + EditorGUILayout.BeginHorizontal(); + { + float scaleSlider = 1; + if (PlayerPrefs.HasKey("All1ShaderRenderImagesScale")) scaleSlider = PlayerPrefs.GetFloat("All1ShaderRenderImagesScale"); + GUILayout.Label("Rendered Image Texture Scale", GUILayout.MaxWidth(190)); + scaleSlider = EditorGUILayout.Slider(scaleSlider, 0.2f, 5f, GUILayout.MaxWidth(200)); + if (GUILayout.Button("Default Value", GUILayout.MaxWidth(100))) PlayerPrefs.SetFloat("All1ShaderRenderImagesScale", 1f); + else PlayerPrefs.SetFloat("All1ShaderRenderImagesScale", scaleSlider); + } + EditorGUILayout.EndVertical(); + GUILayout.Label("Select the folder where new Images will be saved when the Render Material To Image button of the asset component is pressed", EditorStyles.boldLabel); + HandleSaveFolderEditorPref("All1ShaderRenderImages", basePath + renderImagesSavesRelativePath, "Images"); + + DrawLine(Color.grey, 1, 3); + NormalMapCreator(); + + DrawLine(Color.grey, 1, 3); + GradientCreator(); + + DrawLine(Color.grey, 1, 3); + GUILayout.Space(10); + SceneNotificationsToggle(); + + DrawLine(Color.grey, 1, 3); + GUILayout.Space(10); + RefreshLitShader(); + + GUILayout.Space(10); + DrawLine(Color.grey, 1, 3); + GUILayout.Label("Current asset version is " + versionString, EditorStyles.boldLabel); + } + } + + private void ShowImageAndSetImageEditorPref() + { + if(!EditorPrefs.HasKey("allIn1ImageConfig")) + { + EditorPrefs.SetInt("allIn1ImageConfig", (int) ImageType.ShowImage); + } + + imageType = (ImageType) EditorPrefs.GetInt("allIn1ImageConfig"); + if(imageType == ImageType.HideEverywhere) return; + switch(imageType) + { + case ImageType.ShowImage: + case ImageType.HideInComponent: + if(imageInspector == null) imageInspector = GetInspectorImage(); + break; + } + + if(imageInspector) + { + Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(50)); + GUI.DrawTexture(rect, imageInspector, ScaleMode.ScaleToFit, true); + } + DrawLine(Color.grey, 1, 3); + } + + public static Texture2D GetInspectorImage() => GetImage(CUSTOM_EDITOR_HEADER); + + private static Texture2D GetImage(string textureName) + { + string[] guids = AssetDatabase.FindAssets($"{textureName} t:texture"); + if(guids.Length > 0) + { + string path = AssetDatabase.GUIDToAssetPath(guids[0]); + return AssetDatabase.LoadAssetAtPath(path); + } + return null; + } + + private void ShowAssetImageOptionsToggle() + { + GUILayout.Label("Asset Image Display Options", bigLabel); + GUILayout.Space(20); + + int previousImageType = (int) imageType; + imageType = (ImageType) EditorGUILayout.EnumPopup(imageType, GUILayout.MaxWidth(200)); + if((int) imageType != previousImageType) EditorPrefs.SetInt("allIn1ImageConfig", (int) imageType); + + DrawLine(Color.grey, 1, 3); + } + + private void DefaultAssetShader() + { + GUILayout.Label("Default Asset Shader", bigLabel); + GUILayout.Space(20); + GUILayout.Label("This is the shader variant that will be assigned by default to Sprites and UI Images when the asset component is added", EditorStyles.boldLabel); + + bool isUrp = false; + Shader temp = FindShader("AllIn1Urp2dRenderer"); + if (temp != null) isUrp = true; + + shaderTypes = (AllIn1Shader.ShaderTypes)PlayerPrefs.GetInt("allIn1DefaultShader"); + int previousShaderType = (int)shaderTypes; + shaderTypes = (AllIn1Shader.ShaderTypes)EditorGUILayout.EnumPopup(shaderTypes, GUILayout.MaxWidth(200)); + + if (previousShaderType != (int)shaderTypes) + { + if (!isUrp && shaderTypes == AllIn1Shader.ShaderTypes.Urp2dRenderer) + { + showUrpWarning = true; + warningTime = EditorApplication.timeSinceStartup + 5; + } + else + { + PlayerPrefs.SetInt("allIn1DefaultShader", (int)shaderTypes); + showUrpWarning = false; + } + } + + if (warningTime < EditorApplication.timeSinceStartup) showUrpWarning = false; + if (isUrp) showUrpWarning = false; + if (!isUrp && !showUrpWarning && shaderTypes == AllIn1Shader.ShaderTypes.Urp2dRenderer) + { + showUrpWarning = true; + warningTime = EditorApplication.timeSinceStartup + 5; + shaderTypes = AllIn1Shader.ShaderTypes.Default; + PlayerPrefs.SetInt("allIn1DefaultShader", (int)shaderTypes); + } + + if (showUrpWarning) EditorGUILayout.HelpBox( + "You can't set the URP 2D Renderer variant since you didn't import the URP package available in the asset root folder (SEE DOCUMENTATION)", + MessageType.Error, + true); + } + + private void NormalMapCreator() + { + GUILayout.Label("Normal Map Creator", bigLabel); + + GUILayout.Space(20); + GUILayout.Label("Select the folder where new Normal Maps will be saved when the Create Normal Map button of the asset component is pressed (URP only)", EditorStyles.boldLabel); + HandleSaveFolderEditorPref("All1ShaderNormals", basePath + normalMapSavesRelativePath, "Normal Maps"); + + GUILayout.Space(20); + GUILayout.Label("Assign a sprite you want to create a normal map from. Choose the normal map settings and press the 'Create And Save Normal Map' button", EditorStyles.boldLabel); + targetNormalImage = (Texture2D)EditorGUILayout.ObjectField("Target Image", targetNormalImage, typeof(Texture2D), false, GUILayout.MaxWidth(225)); + + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Normal Strength:", GUILayout.MaxWidth(150)); + normalStrength = EditorGUILayout.Slider(normalStrength, 1f, 20f, GUILayout.MaxWidth(400)); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Normal Smoothing:", GUILayout.MaxWidth(150)); + normalSmoothing = EditorGUILayout.IntSlider(normalSmoothing, 0, 3, GUILayout.MaxWidth(400)); + } + EditorGUILayout.EndHorizontal(); + + if (isComputingNormals == 0) + { + if (targetNormalImage != null) + { + if (GUILayout.Button("Create And Save Normal Map")) + { + isComputingNormals = 1; + return; + } + } + else + { + GUILayout.Label("Add a Target Image to use this feature", EditorStyles.boldLabel); + } + } + else + { + GUILayout.Label("Normal Map is currently being created, be patient", EditorStyles.boldLabel, GUILayout.Height(40)); + Repaint(); + isComputingNormals++; + if (isComputingNormals > 5) + { + string assetPath = AssetDatabase.GetAssetPath(targetNormalImage); + var tImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; + if (tImporter != null) + { + tImporter.isReadable = true; + tImporter.SaveAndReimport(); + } + + Texture2D normalToSave = CreateNormalMap(targetNormalImage, normalStrength, normalSmoothing); + + string prefSavedPath = PlayerPrefs.GetString("All1ShaderNormals") + "/"; + string path = prefSavedPath + "NormalMap.png"; + if(System.IO.File.Exists(path)) path = GetNewValidPath(path); + string texName = path.Replace(prefSavedPath, ""); + + path = EditorUtility.SaveFilePanel("Save texture as PNG", prefSavedPath, texName, "png"); + //If you are reading this you might have encountered an error in Unity 2022 Mac builds, if that's the case comment the line above and uncomment the line below + //path = prefSavedPath + texName + ".png"; + + if (path.Length != 0) + { + byte[] pngData = normalToSave.EncodeToPNG(); + if (pngData != null) File.WriteAllBytes(path, pngData); + AssetDatabase.Refresh(); + + if (path.IndexOf("Assets/") >= 0) + { + string subPath = path.Substring(path.IndexOf("Assets/")); + TextureImporter importer = AssetImporter.GetAtPath(subPath) as TextureImporter; + if (importer != null) + { + Debug.Log("Normal Map saved inside the project: " + subPath); + importer.filterMode = FilterMode.Bilinear; + importer.textureType = TextureImporterType.NormalMap; + importer.wrapMode = TextureWrapMode.Repeat; + importer.SaveAndReimport(); + EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(subPath, typeof(Texture))); + } + } + else Debug.Log("Normal Map saved outside the project: " + path); + } + isComputingNormals = 0; + } + } + GUILayout.Label("*This process will freeze the editor for some seconds, larger images will take longer", EditorStyles.boldLabel); + } + + private void HandleSaveFolderEditorPref(string keyName, string defaultPath, string logsFeatureName) + { + if (!PlayerPrefs.HasKey(keyName)) PlayerPrefs.SetString(keyName, defaultPath); + materialTargetFolder = (DefaultAsset)AssetDatabase.LoadAssetAtPath(PlayerPrefs.GetString(keyName), typeof(DefaultAsset)); + if (materialTargetFolder == null) + { + PlayerPrefs.SetString(keyName, defaultPath); + materialTargetFolder = (DefaultAsset)AssetDatabase.LoadAssetAtPath(PlayerPrefs.GetString(keyName), typeof(DefaultAsset)); + if (materialTargetFolder == null) + { + materialTargetFolder = (DefaultAsset)AssetDatabase.LoadAssetAtPath("Assets/", typeof(DefaultAsset)); + if(materialTargetFolder == null) + { + EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(600)); + EditorGUILayout.HelpBox("Folder is invalid, please select a valid one", MessageType.Error, true); + EditorGUILayout.EndHorizontal(); + } + else PlayerPrefs.SetString("Assets/", defaultPath); + } + } + materialTargetFolder = (DefaultAsset)EditorGUILayout.ObjectField("New " + logsFeatureName + " Folder", + materialTargetFolder, typeof(DefaultAsset), false, GUILayout.MaxWidth(500)); + + if (materialTargetFolder != null && IsAssetAFolder(materialTargetFolder)) + { + string path = AssetDatabase.GetAssetPath(materialTargetFolder); + PlayerPrefs.SetString(keyName, path); + EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(600)); + EditorGUILayout.HelpBox("Valid folder! " + logsFeatureName + " save path: " + path, MessageType.Info); + EditorGUILayout.EndHorizontal(); + } + else + { + EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(600)); + EditorGUILayout.HelpBox("Select the new " + logsFeatureName + " Folder", MessageType.Warning, true); + EditorGUILayout.EndHorizontal(); + } + } + + private void GradientCreator() + { + GUILayout.Label("Gradient Creator", bigLabel); + GUILayout.Space(20); + GUILayout.Label("This feature can be used to create textures for the Color Ramp Effect", EditorStyles.boldLabel); + + EditorGUILayout.GradientField("Gradient", gradient, GUILayout.Height(25), GUILayout.MaxWidth(500)); + + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Texture Size:", GUILayout.MaxWidth(145)); + textureSizes = (TextureSizes)EditorGUILayout.EnumPopup(textureSizes, GUILayout.MaxWidth(200)); + } + EditorGUILayout.EndHorizontal(); + + int textureSize = (int)textureSizes; + Texture2D gradTex = new Texture2D(textureSize, 1, TextureFormat.RGBA32, false); + for (int i = 0; i < textureSize; i++) gradTex.SetPixel(i, 0, gradient.Evaluate((float)i / (float)textureSize)); + gradTex.Apply(); + + GUILayout.Space(20); + GUILayout.Label("Select the folder where new Gradient Textures will be saved", EditorStyles.boldLabel); + HandleSaveFolderEditorPref("All1ShaderGradients", basePath + gradientSavesRelativePath, "Gradient"); + + string prefSavedPath = PlayerPrefs.GetString("All1ShaderGradients") + "/"; + if (Directory.Exists(prefSavedPath)) + { + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Gradient Texture Filtering: ", GUILayout.MaxWidth(170)); + gradientFiltering = (FilterMode)EditorGUILayout.EnumPopup(gradientFiltering, GUILayout.MaxWidth(200)); + } + EditorGUILayout.EndHorizontal(); + + if (GUILayout.Button("Save Gradient Texture", GUILayout.MaxWidth(500))) + { + string path = prefSavedPath + "ColorGradient.png"; + if(System.IO.File.Exists(path)) path = GetNewValidPath(path); + string texName = path.Replace(prefSavedPath, ""); + + path = EditorUtility.SaveFilePanel("Save texture as PNG", prefSavedPath, texName, "png"); + if (path.Length != 0) + { + byte[] pngData = gradTex.EncodeToPNG(); + if (pngData != null) File.WriteAllBytes(path, pngData); + AssetDatabase.Refresh(); + + if (path.IndexOf("Assets/") >= 0) + { + string subPath = path.Substring(path.IndexOf("Assets/")); + TextureImporter importer = AssetImporter.GetAtPath(subPath) as TextureImporter; + if (importer != null) + { + Debug.Log("Gradient saved inside the project: " + subPath); + importer.filterMode = gradientFiltering; + importer.SaveAndReimport(); + EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(subPath, typeof(Texture))); + } + } + else Debug.Log("Gradient saved outside the project: " + path); + } + } + } + } + + private static bool IsAssetAFolder(Object obj) + { + string path = ""; + + if (obj == null) return false; + +#if UNITY_6000_3_OR_NEWER + path = AssetDatabase.GetAssetPath(obj.GetEntityId()); +#else + path = AssetDatabase.GetAssetPath(obj.GetInstanceID()); +#endif + + if (path.Length > 0) + { + if (Directory.Exists(path)) return true; + else return false; + } + return false; + } + + private static string GetNewValidPath(string path, string extension = ".png", int i = 1) + { + int number = i; + path = path.Replace(extension, ""); + string newPath = path + "_" + number.ToString(); + string fullPath = newPath + extension; + if(File.Exists(fullPath)) + { + number++; + fullPath = GetNewValidPath(path, extension, number); + } + + return fullPath; + } + + private void DrawLine(Color color, int thickness = 2, int padding = 10) + { + Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness)); + r.height = thickness; + r.y += (padding / 2); + r.x -= 2; + r.width += 6; + EditorGUI.DrawRect(r, color); + } + + public static Texture2D CreateNormalMap(Texture2D t, float normalMult = 5f, int normalSmooth = 0) + { + int width = t.width; + int height = t.height; + Color[] sourcePixels = t.GetPixels(); + Color[] resultPixels = new Color[width * height]; + Vector3 vScale = new Vector3(0.3333f, 0.3333f, 0.3333f); + + for(int y = 0; y < height; y++) + { + for(int x = 0; x < width; x++) + { + int index = x + y * width; + Vector3 cSampleNegXNegY = GetPixelClamped(sourcePixels, x - 1, y - 1, width, height); + Vector3 cSampleZerXNegY = GetPixelClamped(sourcePixels, x, y - 1, width, height); + Vector3 cSamplePosXNegY = GetPixelClamped(sourcePixels, x + 1, y - 1, width, height); + Vector3 cSampleNegXZerY = GetPixelClamped(sourcePixels, x - 1, y, width, height); + Vector3 cSamplePosXZerY = GetPixelClamped(sourcePixels, x + 1, y, width, height); + Vector3 cSampleNegXPosY = GetPixelClamped(sourcePixels, x - 1, y + 1, width, height); + Vector3 cSampleZerXPosY = GetPixelClamped(sourcePixels, x, y + 1, width, height); + Vector3 cSamplePosXPosY = GetPixelClamped(sourcePixels, x + 1, y + 1, width, height); + + float fSampleNegXNegY = Vector3.Dot(cSampleNegXNegY, vScale); + float fSampleZerXNegY = Vector3.Dot(cSampleZerXNegY, vScale); + float fSamplePosXNegY = Vector3.Dot(cSamplePosXNegY, vScale); + float fSampleNegXZerY = Vector3.Dot(cSampleNegXZerY, vScale); + float fSamplePosXZerY = Vector3.Dot(cSamplePosXZerY, vScale); + float fSampleNegXPosY = Vector3.Dot(cSampleNegXPosY, vScale); + float fSampleZerXPosY = Vector3.Dot(cSampleZerXPosY, vScale); + float fSamplePosXPosY = Vector3.Dot(cSamplePosXPosY, vScale); + + float edgeX = (fSampleNegXNegY - fSamplePosXNegY) * 0.25f + (fSampleNegXZerY - fSamplePosXZerY) * 0.5f + (fSampleNegXPosY - fSamplePosXPosY) * 0.25f; + float edgeY = (fSampleNegXNegY - fSampleNegXPosY) * 0.25f + (fSampleZerXNegY - fSampleZerXPosY) * 0.5f + (fSamplePosXNegY - fSamplePosXPosY) * 0.25f; + + Vector2 vEdge = new Vector2(edgeX, edgeY) * normalMult; + Vector3 norm = new Vector3(vEdge.x, vEdge.y, 1.0f).normalized; + resultPixels[index] = new Color(norm.x * 0.5f + 0.5f, norm.y * 0.5f + 0.5f, norm.z * 0.5f + 0.5f, 1); + } + } + + if(normalSmooth > 0) + { + resultPixels = SmoothNormals(resultPixels, width, height, normalSmooth); + } + + Texture2D texNormal = new Texture2D(width, height, TextureFormat.RGB24, false, false); + texNormal.SetPixels(resultPixels); + texNormal.Apply(); + return texNormal; + } + + private static Vector3 GetPixelClamped(Color[] pixels, int x, int y, int width, int height) + { + x = Mathf.Clamp(x, 0, width - 1); + y = Mathf.Clamp(y, 0, height - 1); + Color c = pixels[x + y * width]; + return new Vector3(c.r, c.g, c.b); + } + + private static Color[] SmoothNormals(Color[] pixels, int width, int height, int normalSmooth) + { + Color[] smoothedPixels = new Color[pixels.Length]; + float step = 0.00390625f * normalSmooth; + + for(int y = 0; y < height; y++) + { + for(int x = 0; x < width; x++) + { + float pixelsToAverage = 0.0f; + Color c = pixels[x + y * width]; + pixelsToAverage++; + + for(int offsetY = -normalSmooth; offsetY <= normalSmooth; offsetY++) + { + for(int offsetX = -normalSmooth; offsetX <= normalSmooth; offsetX++) + { + if(offsetX == 0 && offsetY == 0) continue; + + int sampleX = Mathf.Clamp(x + offsetX, 0, width - 1); + int sampleY = Mathf.Clamp(y + offsetY, 0, height - 1); + + c += pixels[sampleX + sampleY * width]; + pixelsToAverage++; + } + } + + smoothedPixels[x + y * width] = c / pixelsToAverage; + } + } + + return smoothedPixels; + } + + [MenuItem("Assets/Create/AllIn1Shader Materials/CreateDefaultMaterial")] + public static void CreateDefaultMaterial() + { + CreateMaterial("AllIn1SpriteShader"); + } + + [MenuItem("Assets/Create/AllIn1Shader Materials/CreateScaledTimeMaterial")] + public static void CreateScaledTimeMaterial() + { + CreateMaterial("AllIn1SpriteShaderScaledTime"); + } + + [MenuItem("Assets/Create/AllIn1Shader Materials/CreateUiMaskMaterial")] + public static void CreateUiMaskMaterial() + { + CreateMaterial("AllIn1SpriteShaderUiMask"); + } + + private static void CreateMaterial(string shaderName) + { + string selectedPath = AssetDatabase.GetAssetPath(Selection.activeObject); + + if(!string.IsNullOrEmpty(selectedPath) && Directory.Exists(selectedPath)) + { + Material material = new Material(FindShader(shaderName)); + string fullPath = selectedPath + "/Mat-" + shaderName + ".mat"; + if(File.Exists(fullPath)) fullPath = GetNewValidPath(fullPath, ".mat"); + AssetDatabase.CreateAsset(material, fullPath); + AssetDatabase.Refresh(); + } + else + { + Debug.LogWarning("Please select a valid folder in the Project Window."); + } + } + + private void OnEnable() => GetBasePath(); + + private static void GetBasePath() + { + string[] guids = AssetDatabase.FindAssets("t:folder AllIn1SpriteShader"); + if(guids.Length > 0) + { + basePath = AssetDatabase.GUIDToAssetPath(guids[0]); + } + else + { + Debug.LogError("AllIn1SpriteShader folder not found in the project."); + basePath = "Assets/Plugins/AllIn1SpriteShader"; + } + } + + public static string GetMaterialSavePath() + { + if(!PlayerPrefs.HasKey("All1ShaderMaterials")) + { + GetBasePath(); + return basePath + materialsSavesRelativePath; + } + return PlayerPrefs.GetString("All1ShaderMaterials"); + } + + public static string GetRenderImageSavePath() + { + if(!PlayerPrefs.HasKey("All1ShaderRenderImages")) + { + GetBasePath(); + return basePath + renderImagesSavesRelativePath; + } + return PlayerPrefs.GetString("All1ShaderRenderImages"); + } + + public static string GetNormalMapSavePath() + { + if(!PlayerPrefs.HasKey("All1ShaderNormals")) + { + GetBasePath(); + return basePath + normalMapSavesRelativePath; + } + return PlayerPrefs.GetString("All1ShaderNormals"); + } + + private void SceneNotificationsToggle() + { + float previousLabelWidth = EditorGUIUtility.labelWidth; + EditorGUIUtility.labelWidth = 200f; + bool areNotificationsEnabled = EditorPrefs.GetInt("DisplaySceneViewNotifications", 1) == 1; + areNotificationsEnabled = EditorGUILayout.Toggle("Display Scene View Notifications", areNotificationsEnabled); + EditorPrefs.SetInt("DisplaySceneViewNotifications", areNotificationsEnabled ? 1 : 0); + EditorGUIUtility.labelWidth = previousLabelWidth; + } + + private static void RefreshLitShader() + { + GUILayout.Label("Force the Lit Shader to be reconfigured"); + GUILayout.Label("If you are getting some error or have changed the render pipeline press the button below"); + if (GUILayout.Button("Refresh Lit Shader", GUILayout.MaxWidth(500f))) + { + AllIn1ShaderImporter.ForceReimport(); + } + } + + public static void SceneViewNotificationAndLog(string message) + { + Debug.Log(message); + ShowSceneViewNotification(message); + } + + public static void ShowSceneViewNotification(string message) + { + bool showNotification = EditorPrefs.GetInt("DisplaySceneViewNotifications", 1) == 1; + if(!showNotification) return; + + GUIContent content = new GUIContent(message); +#if UNITY_2019_1_OR_NEWER + SceneView.lastActiveSceneView.ShowNotification(content, 1.5f); +#else + SceneView.lastActiveSceneView.ShowNotification(content); +#endif + } + + public static Shader FindShader(string shaderName) + { + string[] guids = AssetDatabase.FindAssets($"{shaderName} t:shader"); + foreach(string guid in guids) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + Shader shader = AssetDatabase.LoadAssetAtPath(path); + if(shader != null) + { + string fullShaderName = shader.name; + string actualShaderName = fullShaderName.Substring(fullShaderName.LastIndexOf('/') + 1); + if(actualShaderName.Equals(shaderName)) return shader; + } + } + return null; + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs.meta new file mode 100644 index 0000000..eba6416 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: b642652081667ab4fad9f2579fec0e51 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/AllIn1ShaderWindow.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor.meta new file mode 100644 index 0000000..4d7651e --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 88005189a0eaefe4aa34961fe0208e26 +folderAsset: yes +timeCreated: 1464994693 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn12DRendererMaterialInspector.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn12DRendererMaterialInspector.cs new file mode 100644 index 0000000..ba3c2ee --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn12DRendererMaterialInspector.cs @@ -0,0 +1,894 @@ +#if UNITY_EDITOR +using System.Linq; +using AllIn1SpriteShader; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; +using UnityEngine.Rendering; + +namespace AllIn1SpriteShader +{ + [CanEditMultipleObjects] + public class AllIn12DRendererMaterialInspector : ShaderGUI + { + private Material targetMat; + private BlendMode srcMode, dstMode; + private CompareFunction zTestMode = CompareFunction.LessEqual; + private CullMode cullMode; + + private GUIStyle propertiesStyle, bigLabelStyle, smallLabelStyle, toggleButtonStyle; + private const int bigFontSize = 16, smallFontSize = 11; + private string[] oldKeyWords; + private int effectCount = 1; + private Material originalMaterialCopy; + private MaterialEditor matEditor; + private MaterialProperty[] matProperties; + private uint[] materialDrawers = new uint[] { 1, 2, 4, 8 }; + bool[] currEnabledDrawers; + private const uint advancedConfigDrawer = 0; + private const uint colorFxShapeDrawer = 1; + private const uint uvFxShapeDrawer = 2; + private const uint lightingDrawer = 3; + + public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) + { + matEditor = materialEditor; + matProperties = properties; + targetMat = materialEditor.target as Material; + effectCount = 1; + oldKeyWords = targetMat.shaderKeywords; + propertiesStyle = new GUIStyle(EditorStyles.helpBox); + propertiesStyle.margin = new RectOffset(0, 0, 0, 0); + bigLabelStyle = new GUIStyle(EditorStyles.boldLabel); + bigLabelStyle.fontSize = bigFontSize; + smallLabelStyle = new GUIStyle(EditorStyles.boldLabel); + smallLabelStyle.fontSize = smallFontSize; + toggleButtonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleCenter, richText = true }; + currEnabledDrawers = new bool[materialDrawers.Length]; + uint iniDrawers = (uint)ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue; + for(int i = 0; i < materialDrawers.Length; i++) currEnabledDrawers[i] = (materialDrawers[i] & iniDrawers) > 0; + + GUILayout.Label("General Properties", bigLabelStyle); + DrawProperty(0); + DrawProperty(177); + DrawProperty(1); + DrawProperty(2); + + currEnabledDrawers[advancedConfigDrawer] = GUILayout.Toggle(currEnabledDrawers[advancedConfigDrawer], new GUIContent("Show Advanced Configuration"), toggleButtonStyle); + if(currEnabledDrawers[advancedConfigDrawer]) + { + + EditorGUILayout.BeginVertical(propertiesStyle); + Blending(); + DrawLine(Color.grey, 1, 3); + Culling(); + DrawLine(Color.grey, 1, 3); + ZTest(); + DrawLine(Color.grey, 1, 3); + ZWrite(); + DrawLine(Color.grey, 1, 3); + Billboard("Bilboard active", "BILBOARD_ON"); + DrawLine(Color.grey, 1, 3); + SpriteAtlas("Sprite inside an atlas?", "ATLAS_ON"); + DrawLine(Color.grey, 1, 3); + materialEditor.EnableInstancingField(); + DrawLine(Color.grey, 1, 3); + materialEditor.RenderQueueField(); + EditorGUILayout.EndVertical(); + } + + DrawLine(Color.grey, 1, 3); + GUILayout.Label("Lighting Properties", bigLabelStyle); + currEnabledDrawers[lightingDrawer] = GUILayout.Toggle(currEnabledDrawers[lightingDrawer], new GUIContent("Show Lighting Properties"), toggleButtonStyle); + if(currEnabledDrawers[lightingDrawer]) + { + for (int i = 172; i <= 175; i++) DrawProperty(i); + DrawProperty(176, true); + MaterialProperty glowLight = properties[176]; + if (glowLight.floatValue == 1) targetMat.EnableKeyword("GLOWLIGHT_ON"); + else targetMat.DisableKeyword("GLOWLIGHT_ON"); + } + + EditorGUILayout.Separator(); + DrawLine(Color.grey, 1, 3); + GUILayout.Label("Color Effects", bigLabelStyle); + + currEnabledDrawers[colorFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[colorFxShapeDrawer], new GUIContent("Show Color Effects"), toggleButtonStyle); + if(currEnabledDrawers[colorFxShapeDrawer]) + { + Glow("Glow", "GLOW_ON"); + Fade("Fade", "FADE_ON"); + + Outline("Outline", "OUTBASE_ON"); + GenericEffect("Alpha Outline", "ALPHAOUTLINE_ON", 26, 30, true, "A more performant but less flexible outline"); + InnerOutline("Inner Outline", "INNEROUTLINE_ON", 66, 69); + Gradient("Gradient & Radial Gradient", "GRADIENT_ON"); + GenericEffect("Color Swap", "COLORSWAP_ON", 36, 42, true, "You will need a mask texture (see Documentation)", new int[] { 154 }); + GenericEffect("Hue Shift", "HSV_ON", 43, 45); + ColorChange("Change 1 Color", "CHANGECOLOR_ON"); + ColorRamp("Color Ramp", "COLORRAMP_ON"); + GenericEffect("Hit Effect", "HITEFFECT_ON", 46, 48); + GenericEffect("Negative", "NEGATIVE_ON", 49, 49); + GenericEffect("Pixelate", "PIXELATE_ON", 50, 50, true, "Looks bad with distorition effects"); + GreyScale("GreyScale", "GREYSCALE_ON"); + Posterize("Posterize", "POSTERIZE_ON"); + Blur("Blur", "BLUR_ON"); + GenericEffect("Motion Blur", "MOTIONBLUR_ON", 62, 63); + GenericEffect("Ghost", "GHOST_ON", 64, 65, true, "This effect will not affect the outline", new int[] { 157 }); + GenericEffect("Hologram", "HOLOGRAM_ON", 73, 77, true, null, new int[] { 140, 158 }); + GenericEffect("Chromatic Aberration", "CHROMABERR_ON", 78, 79); + GenericEffect("Glitch", "GLITCH_ON", 80, 80, true, null, new int[] { 139, 184 }); + GenericEffect("Flicker", "FLICKER_ON", 81, 83); + GenericEffect("Shadow", "SHADOW_ON", 84, 87); + GenericEffect("Shine", "SHINE_ON", 133, 138); + GenericEffect("Contrast & Brightness", "CONTRAST_ON", 152, 153); + Overlay("Overlay Texture", "OVERLAY_ON"); + GenericEffect("Alpha Cutoff", "ALPHACUTOFF_ON", 70, 70); + GenericEffect("Alpha Round", "ALPHAROUND_ON", 144, 144); + } + + DrawLine(Color.grey, 1, 3); + GUILayout.Label("UV Effects", bigLabelStyle); + + currEnabledDrawers[uvFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[uvFxShapeDrawer], new GUIContent("Show Alpha Effects"), toggleButtonStyle); + if(currEnabledDrawers[uvFxShapeDrawer]) + { + GenericEffect("Hand Drawn", "DOODLE_ON", 88, 89); + Grass("Grass Movement / Wind", "WIND_ON"); + GenericEffect("Wave", "WAVEUV_ON", 94, 98); + GenericEffect("Round Wave", "ROUNDWAVEUV_ON", 127, 128); + GenericEffect("Rect Size (Enable wireframe to see result)", "RECTSIZE_ON", 99, 99, true, "Only on single sprites spritesheets NOT supported"); + GenericEffect("Offset", "OFFSETUV_ON", 100, 101); + GenericEffect("Clipping / Fill Amount", "CLIPPING_ON", 102, 105); + GenericEffect("Radial Clipping / Radial Fill", "RADIALCLIPPING_ON", 164, 166); + GenericEffect("Texture Scroll", "TEXTURESCROLL_ON", 106, 107, true, "Set Texture Wrap Mode to Repeat"); + GenericEffect("Zoom", "ZOOMUV_ON", 108, 108); + GenericEffect("Distortion", "DISTORT_ON", 109, 112, true, null, new int[] { 182 }); + GenericEffect("Warp Distortion", "WARP_ON", 167, 169); + GenericEffect("Twist", "TWISTUV_ON", 113, 116); + GenericEffect("Rotate", "ROTATEUV_ON", 117, 117, true, "_Tip_ Use Clipping effect to avoid possible undesired parts"); + GenericEffect("Polar Coordinates (Tile texture for good results)", "POLARUV_ON", -1, -1); + GenericEffect("Fish Eye", "FISHEYE_ON", 118, 118); + GenericEffect("Pinch", "PINCH_ON", 119, 119); + GenericEffect("Shake", "SHAKEUV_ON", 120, 122); + } + + SetAndSaveEnabledDrawers(iniDrawers); + } + + private void SetAndSaveEnabledDrawers(uint iniDrawers) + { + uint currDrawers = 0; + for(int i = 0; i < currEnabledDrawers.Length; i++) + { + if(currEnabledDrawers[i]) currDrawers |= materialDrawers[i]; + } + + if(iniDrawers != currDrawers) ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue = currDrawers; + } + + private void Blending() + { + MaterialProperty srcM = ShaderGUI.FindProperty("_MySrcMode", matProperties); + MaterialProperty dstM = ShaderGUI.FindProperty("_MyDstMode", matProperties); + if(srcM.floatValue == 0 && dstM.floatValue == 0) + { + srcM.floatValue = 5; + dstM.floatValue = 10; + } + + GUILayout.Label("Look for 'ShaderLab: Blending' if you don't know what this is", smallLabelStyle); + if(GUILayout.Button("Back To Default Blending")) + { + srcM.floatValue = 5; + dstM.floatValue = 10; + targetMat.DisableKeyword("PREMULTIPLYALPHA_ON"); + } + + srcMode = (BlendMode)srcM.floatValue; + dstMode = (BlendMode)dstM.floatValue; + srcMode = (BlendMode)EditorGUILayout.EnumPopup("SrcMode", srcMode); + dstMode = (BlendMode)EditorGUILayout.EnumPopup("DstMode", dstMode); + srcM.floatValue = (float)(srcMode); + dstM.floatValue = (float)(dstMode); + + bool ini = oldKeyWords.Contains("PREMULTIPLYALPHA_ON"); + bool toggle = EditorGUILayout.Toggle("Premultiply Alpha?", ini); + if(ini != toggle) Save(); + if(toggle) targetMat.EnableKeyword("PREMULTIPLYALPHA_ON"); + else targetMat.DisableKeyword("PREMULTIPLYALPHA_ON"); + } + + private void Billboard(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = inspector; + toggle = GUILayout.Toggle(toggle, effectNameLabel); + + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + GUILayout.Label("Don't use this feature on UI elements!", smallLabelStyle); + DrawProperty(129, true); + MaterialProperty billboardY = matProperties[129]; + if(billboardY.floatValue == 1) targetMat.EnableKeyword("BILBOARDY_ON"); + else targetMat.DisableKeyword("BILBOARDY_ON"); + } + else targetMat.DisableKeyword(keyword); + } + + private void ZWrite() + { + MaterialProperty zWrite = ShaderGUI.FindProperty("_ZWrite", matProperties); + bool toggle = zWrite.floatValue > 0.9f ? true : false; + EditorGUILayout.BeginHorizontal(); + { + float tempValue = zWrite.floatValue; + toggle = GUILayout.Toggle(toggle, new GUIContent("Enable Z Write")); + if(toggle) zWrite.floatValue = 1.0f; + else zWrite.floatValue = 0.0f; + if(tempValue != zWrite.floatValue && !Application.isPlaying) Save(); + } + EditorGUILayout.EndHorizontal(); + } + + private void ZTest() + { + MaterialProperty zTestM = ShaderGUI.FindProperty("_ZTestMode", matProperties); + float tempValue = zTestM.floatValue; + zTestMode = (UnityEngine.Rendering.CompareFunction)zTestM.floatValue; + zTestMode = (UnityEngine.Rendering.CompareFunction)EditorGUILayout.EnumPopup("Z TestMode", zTestMode); + zTestM.floatValue = (float)(zTestMode); + if(tempValue != zTestM.floatValue && !Application.isPlaying) Save(); + } + + private void Culling() + { + MaterialProperty cullO = ShaderGUI.FindProperty("_CullingOption", matProperties);; + float tempValue = cullO.floatValue; + cullMode = (UnityEngine.Rendering.CullMode)cullO.floatValue; + cullMode = (UnityEngine.Rendering.CullMode)EditorGUILayout.EnumPopup("Culling Mode", cullMode); + cullO.floatValue = (float)(cullMode); + if(tempValue != cullO.floatValue && !Application.isPlaying) Save(); + } + + private void SpriteAtlas(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + toggle = GUILayout.Toggle(toggle, inspector); + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + EditorGUILayout.BeginVertical(propertiesStyle); + { + GUILayout.Label("Make sure SpriteAtlasUV component is added \n " + + "*Check documentation if unsure what this does or how it works", smallLabelStyle); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + } + + private void Fade(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + ".Fade"; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if (ini != toggle) Save(); + if (toggle) + { + targetMat.EnableKeyword(keyword); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(7); + DrawProperty(178); + + DrawProperty(8); + DrawProperty(9); + DrawProperty(10); + DrawProperty(11); + + DrawProperty(12); + DrawProperty(179); + + DrawProperty(13); + } + EditorGUILayout.EndVertical(); + } + else + { + targetMat.DisableKeyword(keyword); + } + + EditorGUILayout.EndToggleGroup(); + } + + private void Outline(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + ".Outline"; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("OUTBASE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(14); + DrawProperty(15); + DrawProperty(16); + DrawEffectSubKeywordToggle("Outline High Resolution?", "OUTBASE8DIR_ON"); + + DrawLine(Color.grey, 1, 3); + bool outlinePixelPerf = DrawEffectSubKeywordToggle("Outline is Pixel Perfect?", "OUTBASEPIXELPERF_ON"); + if(outlinePixelPerf) DrawProperty(18); + else DrawProperty(17); + + DrawLine(Color.grey, 1, 3); + bool outlineTexture = DrawEffectSubKeywordToggle("Outline uses texture?", "OUTTEX_ON"); + if(outlineTexture) + { + DrawProperty(19); + DrawProperty(20); + DrawProperty(21); + DrawProperty(180); + } + + DrawLine(Color.grey, 1, 3); + bool outlineDistort = DrawEffectSubKeywordToggle("Outline uses distortion?", "OUTDIST_ON"); + if(outlineDistort) + { + DrawProperty(22); + DrawProperty(23); + DrawProperty(24); + DrawProperty(25); + DrawProperty(181); + } + + DrawLine(Color.grey, 1, 3); + DrawEffectSubKeywordToggle("Only render outline?", "ONLYOUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("OUTBASE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void GenericEffect(string inspector, string keyword, int first, int last, bool effectCounter = true, string preMessage = null, int[] extraProperties = null, bool boldToggleLetters = true) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + if(effectCounter) + { + effectNameLabel.text = effectCount + "." + inspector; + effectCount++; + } + else effectNameLabel.text = inspector; + if(boldToggleLetters) toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + else toggle = GUILayout.Toggle(toggle, effectNameLabel); + + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + if(first > 0) + { + EditorGUILayout.BeginVertical(propertiesStyle); + { + if(preMessage != null) GUILayout.Label(preMessage, smallLabelStyle); + for(int i = first; i <= last; i++) DrawProperty(i); + if(extraProperties != null) + foreach(int i in extraProperties) + DrawProperty(i); + } + EditorGUILayout.EndVertical(); + } + } + else targetMat.DisableKeyword(keyword); + + if(boldToggleLetters) EditorGUILayout.EndToggleGroup(); + } + + private void Glow(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("GLOW_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool useGlowTex = DrawEffectSubKeywordToggle("Use Glow Texture?", "GLOWTEX_ON"); + if(useGlowTex) DrawProperty(6); + + DrawProperty(3); + DrawProperty(4); + DrawProperty(5, true); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("GLOW_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void ColorRamp(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("COLORRAMP_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool useEditableGradient = false; + if(AssetDatabase.Contains(targetMat)) + { + useEditableGradient = oldKeyWords.Contains("GRADIENTCOLORRAMP_ON"); + bool gradientTex = useEditableGradient; + gradientTex = GUILayout.Toggle(gradientTex, new GUIContent("Use Editable Gradient?")); + if(useEditableGradient != gradientTex) + { + Save(); + if(gradientTex) + { + useEditableGradient = true; + targetMat.EnableKeyword("GRADIENTCOLORRAMP_ON"); + } + else targetMat.DisableKeyword("GRADIENTCOLORRAMP_ON"); + } + + if(useEditableGradient) matEditor.ShaderProperty(matProperties[159], matProperties[159].displayName); + } + else GUILayout.Label("*Save to folder to allow for dynamic Gradient property", smallLabelStyle); + + if(!useEditableGradient) DrawProperty(51); + + DrawProperty(52); + DrawProperty(53, true); + MaterialProperty colorRampOut = matProperties[53]; + if(colorRampOut.floatValue == 1) targetMat.EnableKeyword("COLORRAMPOUTLINE_ON"); + else targetMat.DisableKeyword("COLORRAMPOUTLINE_ON"); + DrawProperty(155); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("COLORRAMP_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void ColorChange(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("CHANGECOLOR_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + for(int i = 123; i < 127; i++) DrawProperty(i); + + DrawLine(Color.grey, 1, 3); + ini = oldKeyWords.Contains("CHANGECOLOR2_ON"); + bool toggle2 = ini; + toggle2 = EditorGUILayout.Toggle("Use Color 2", ini); + if(ini != toggle2) Save(); + if(toggle2) + { + targetMat.EnableKeyword("CHANGECOLOR2_ON"); + for(int i = 146; i < 149; i++) DrawProperty(i); + } + else targetMat.DisableKeyword("CHANGECOLOR2_ON"); + + DrawLine(Color.grey, 1, 3); + ini = oldKeyWords.Contains("CHANGECOLOR3_ON"); + toggle2 = ini; + toggle2 = EditorGUILayout.Toggle("Use Color 3", toggle2); + if(ini != toggle2) Save(); + if(toggle2) + { + targetMat.EnableKeyword("CHANGECOLOR3_ON"); + for(int i = 149; i < 152; i++) DrawProperty(i); + } + else targetMat.DisableKeyword("CHANGECOLOR3_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("CHANGECOLOR_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void GreyScale(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("GREYSCALE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(54); + DrawProperty(56); + DrawProperty(55, true); + MaterialProperty greyScaleOut = matProperties[55]; + if(greyScaleOut.floatValue == 1) targetMat.EnableKeyword("GREYSCALEOUTLINE_ON"); + else targetMat.DisableKeyword("GREYSCALEOUTLINE_ON"); + DrawProperty(156); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("GREYSCALE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Posterize(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("POSTERIZE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(57); + DrawProperty(58); + DrawProperty(59, true); + MaterialProperty posterizeOut = matProperties[59]; + if(posterizeOut.floatValue == 1) targetMat.EnableKeyword("POSTERIZEOUTLINE_ON"); + else targetMat.DisableKeyword("POSTERIZEOUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("POSTERIZE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Blur(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("BLUR_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + GUILayout.Label("This effect will not affect the outline", smallLabelStyle); + DrawProperty(60); + DrawProperty(61, true); + MaterialProperty blurIsHd = matProperties[61]; + if(blurIsHd.floatValue == 1) targetMat.EnableKeyword("BLURISHD_ON"); + else targetMat.DisableKeyword("BLURISHD_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("BLUR_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Grass(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("WIND_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(90); + DrawProperty(91); + DrawProperty(145); + DrawProperty(92); + DrawProperty(93, true); + MaterialProperty grassManual = matProperties[92]; + if(grassManual.floatValue == 1) targetMat.EnableKeyword("MANUALWIND_ON"); + else targetMat.DisableKeyword("MANUALWIND_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("WIND_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void InnerOutline(string inspector, string keyword, int first, int last) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + if(first > 0) + { + EditorGUILayout.BeginVertical(propertiesStyle); + { + for(int i = first; i <= last; i++) DrawProperty(i); + + EditorGUILayout.Separator(); + DrawProperty(72, true); + MaterialProperty onlyInOutline = matProperties[72]; + if(onlyInOutline.floatValue == 1) targetMat.EnableKeyword("ONLYINNEROUTLINE_ON"); + else targetMat.DisableKeyword("ONLYINNEROUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void Gradient(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(143, true); + MaterialProperty gradIsRadial = matProperties[143]; + if(gradIsRadial.floatValue == 1) + { + targetMat.EnableKeyword("RADIALGRADIENT_ON"); + DrawProperty(31); + DrawProperty(32); + DrawProperty(34); + DrawProperty(141); + } + else + { + targetMat.DisableKeyword("RADIALGRADIENT_ON"); + bool simpleGradient = oldKeyWords.Contains("GRADIENT2COL_ON"); + bool simpleGradToggle = EditorGUILayout.Toggle("2 Color Gradient?", simpleGradient); + if(simpleGradient && !simpleGradToggle) targetMat.DisableKeyword("GRADIENT2COL_ON"); + else if(!simpleGradient && simpleGradToggle) targetMat.EnableKeyword("GRADIENT2COL_ON"); + DrawProperty(31); + DrawProperty(32); + if(!simpleGradToggle) DrawProperty(33); + DrawProperty(34); + if(!simpleGradToggle) DrawProperty(35); + if(!simpleGradToggle) DrawProperty(141); + DrawProperty(142); + } + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void Overlay(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool multModeOn = oldKeyWords.Contains("OVERLAYMULT_ON"); + bool isMultMode = multModeOn; + isMultMode = GUILayout.Toggle(isMultMode, new GUIContent("Is overlay multiplicative?")); + if(multModeOn != isMultMode) + { + Save(); + if(isMultMode) + { + multModeOn = true; + targetMat.EnableKeyword("OVERLAYMULT_ON"); + } + else targetMat.DisableKeyword("OVERLAYMULT_ON"); + } + + if(multModeOn) GUILayout.Label("Overlay is set to multiplicative mode", smallLabelStyle); + else GUILayout.Label("Overlay is set to additive mode", smallLabelStyle); + + DrawProperty(160); + DrawProperty(183); + DrawProperty(161); + DrawProperty(162); + DrawProperty(163); + + + for(int i = 170; i <= 171; i++) DrawProperty(i); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void DrawProperty(int index, bool noReset = false) + { + MaterialProperty targetProperty = matProperties[index]; + + EditorGUILayout.BeginHorizontal(); + { + GUIContent propertyLabel = new GUIContent(); + propertyLabel.text = targetProperty.displayName; + propertyLabel.tooltip = targetProperty.name + " (C#)"; + + matEditor.ShaderProperty(targetProperty, propertyLabel); + + if(!noReset) + { + GUIContent resetButtonLabel = new GUIContent(); + resetButtonLabel.text = "R"; + resetButtonLabel.tooltip = "Resets to default value"; + if(GUILayout.Button(resetButtonLabel, GUILayout.Width(20))) ResetProperty(targetProperty); + } + } + EditorGUILayout.EndHorizontal(); + } + + private void ResetProperty(MaterialProperty targetProperty) + { + AllIn1ShaderPropertyType propertyType = EditorUtils.GetShaderTypeByMaterialProperty(targetProperty); + + if(originalMaterialCopy == null) originalMaterialCopy = new Material(targetMat.shader); + if(propertyType == AllIn1ShaderPropertyType.Float || propertyType == AllIn1ShaderPropertyType.Range) + { + targetProperty.floatValue = originalMaterialCopy.GetFloat(targetProperty.name); + } + else if(propertyType == AllIn1ShaderPropertyType.Vector) + { + targetProperty.vectorValue = originalMaterialCopy.GetVector(targetProperty.name); + } + else if(propertyType == AllIn1ShaderPropertyType.Color) + { + targetProperty.colorValue = originalMaterialCopy.GetColor(targetProperty.name); + } + else if(propertyType == AllIn1ShaderPropertyType.Texture) + { + targetProperty.textureValue = originalMaterialCopy.GetTexture(targetProperty.name); + } + } + + private bool DrawEffectSubKeywordToggle(string inspector, string keyword, bool setCustomConfigAfter = false) + { + GUIContent propertyLabel = new GUIContent(); + propertyLabel.text = inspector; + propertyLabel.tooltip = keyword + " (C#)"; + + bool ini = oldKeyWords.Contains(keyword); + bool toggle = ini; + toggle = GUILayout.Toggle(toggle, propertyLabel); + if(ini != toggle) + { + if(toggle) targetMat.EnableKeyword(keyword); + else targetMat.DisableKeyword(keyword); + } + + return toggle; + } + + private void Save() + { + if(!Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + EditorUtility.SetDirty(targetMat); + } + + private void DrawLine(Color color, int thickness = 2, int padding = 10) + { + Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness)); + r.height = thickness; + r.y += (padding / 2); + r.x -= 2; + r.width += 6; + EditorGUI.DrawRect(r, color); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn12DRendererMaterialInspector.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn12DRendererMaterialInspector.cs.meta new file mode 100644 index 0000000..d266bc1 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn12DRendererMaterialInspector.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: e063793833d64b7439fd1f34dc70b052 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn12DRendererMaterialInspector.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderAssetPostProcessor.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderAssetPostProcessor.cs new file mode 100644 index 0000000..6ae0a26 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderAssetPostProcessor.cs @@ -0,0 +1,26 @@ +#if UNITY_EDITOR +using UnityEditor; + +namespace AllIn1SpriteShader +{ + public class AllIn1ShaderAssetPostProcessor : AssetPostprocessor + { + static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload) + { + bool needToRefreshConfig = false; + for (int i = 0; i < importedAssets.Length; i++) + { + if (importedAssets[i].EndsWith(Constants.MAIN_ASSEMBLY_NAME)) + { + needToRefreshConfig = needToRefreshConfig || true; + } + } + + if (needToRefreshConfig) + { + AllIn1ShaderImporter.ForceReimport(); + } + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderAssetPostProcessor.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderAssetPostProcessor.cs.meta new file mode 100644 index 0000000..0c14811 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderAssetPostProcessor.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 9ab4f76bf224f2b4d8735f59db902c37 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderAssetPostProcessor.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderGradientDrawer.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderGradientDrawer.cs new file mode 100644 index 0000000..0f49833 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderGradientDrawer.cs @@ -0,0 +1,283 @@ +#if UNITY_EDITOR +using System; +using System.Linq; +using System.Reflection; +using UnityEditor; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace AllIn1SpriteShader +{ + public class AllIn1ShaderGradientDrawer : MaterialPropertyDrawer + { + private int resolution; + private Texture2D textureAsset; + private static MethodInfo reinitializeMethod; + private static MethodInfo resizeMethod; + + public AllIn1ShaderGradientDrawer() + { + resolution = 64; + } + + public AllIn1ShaderGradientDrawer(float res) + { + resolution = (int)res; + } + + private static bool IsPropertyTypeSuitable(MaterialProperty prop) + { + AllIn1ShaderPropertyType propertyType = EditorUtils.GetShaderTypeByMaterialProperty(prop); + return propertyType == AllIn1ShaderPropertyType.Texture; + } + + private string TextureName(MaterialProperty prop) => $"z{prop.name}Tex"; + private string OldName(MaterialProperty prop) => $"{prop.name}Tex"; + + public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) + { + if (!IsPropertyTypeSuitable(prop)) + { + EditorGUI.HelpBox(position, $"[Gradient] used on non-texture property \"{prop.name}\"", MessageType.Error); + return; + } + + if (!AssetDatabase.Contains(prop.targets.FirstOrDefault())) + { + EditorGUI.HelpBox(position, "Save Material To Folder to use this effect. Or use the regular Color Ramp instead", MessageType.Error); + return; + } + + string textureName = TextureName(prop); + string oldTextureName = OldName(prop); + + Gradient currentGradient = null; + if (prop.targets.Length == 1) + { + Material target = (Material)prop.targets[0]; + string path = AssetDatabase.GetAssetPath(target); + textureAsset = GetTexture(path, textureName, oldTextureName); + if (textureAsset != null) currentGradient = DecodeGradient(prop, textureAsset.name); + if (currentGradient == null) currentGradient = new Gradient() { }; + + EditorGUI.showMixedValue = false; + } + else + { + EditorGUI.showMixedValue = true; + } + + using (EditorGUI.ChangeCheckScope changeScope = new EditorGUI.ChangeCheckScope()) + { + currentGradient = EditorGUILayout.GradientField(label, currentGradient, GUILayout.Height(15)); + + if (changeScope.changed) + { + string encodedGradient = EncodeGradient(currentGradient); + string fullAssetName = textureName + encodedGradient; + foreach (Object target in prop.targets) + { + if (!AssetDatabase.Contains(target)) continue; + + string path = AssetDatabase.GetAssetPath(target); + Texture2D textureAsset = GetTexture(path, textureName, oldTextureName); + Undo.RecordObject(textureAsset, "Change Material Gradient"); + textureAsset.name = fullAssetName; + BakeGradient(currentGradient, textureAsset); + EditorUtility.SetDirty(textureAsset); + + Material material = (Material)target; + material.SetTexture(prop.name, textureAsset); + } + } + } + EditorGUI.showMixedValue = false; + } + + private Texture2D GetTexture(string path, string name, string possibleOldName) + { + textureAsset = GetTextureAsset(path, name); + if(textureAsset == null) + { + textureAsset = GetTextureAsset(path, possibleOldName); + if(textureAsset != null) + { + textureAsset.name = textureAsset.name.Replace(possibleOldName, name); + EditorUtility.SetDirty(textureAsset); + } + } + if (textureAsset == null) CreateTexture(path, name); + if(textureAsset.width != resolution) + { + ResizeTexture(textureAsset, resolution, 1); + EditorUtility.SetDirty(textureAsset); + AssetDatabase.SaveAssets(); + } + return textureAsset; + } + + private void ResizeTexture(Texture2D texture, int width, int height) + { + if(reinitializeMethod == null && resizeMethod == null) + { + reinitializeMethod = typeof(Texture2D).GetMethod("Reinitialize", new[] { typeof(int), typeof(int) }); + if(reinitializeMethod == null) resizeMethod = typeof(Texture2D).GetMethod("Resize", new[] { typeof(int), typeof(int) }); + } + + if(reinitializeMethod != null) reinitializeMethod.Invoke(texture, new object[] { width, height }); + else if(resizeMethod != null) resizeMethod.Invoke(texture, new object[] { width, height }); + } + + private void CreateTexture(string path, string name = "unnamed texture") + { + textureAsset = new Texture2D(resolution, 1, TextureFormat.RGBA32, false); + textureAsset.wrapMode = TextureWrapMode.Clamp; + textureAsset.filterMode = FilterMode.Bilinear; + textureAsset.name = name; + AssetDatabase.AddObjectToAsset(textureAsset, path); + AssetDatabase.Refresh(); + } + + private string EncodeGradient(Gradient gradient) + { + if (gradient == null) return null; + return JsonUtility.ToJson(new GradientRepresentation(gradient)); + } + + private Gradient DecodeGradient(MaterialProperty prop, string name) + { + string json = name.Substring(TextureName(prop).Length); + try + { + return JsonUtility.FromJson(json).ToGradient(); + } + catch (Exception) + { + return null; + } + } + + private Texture2D GetTextureAsset(string path, string name) + { + return AssetDatabase.LoadAllAssetsAtPath(path).FirstOrDefault(asset => asset.name.StartsWith(name)) as Texture2D; + } + + private void BakeGradient(Gradient gradient, Texture2D texture) + { + if (gradient == null) return; + for (int x = 0; x < texture.width; x++) + { + Color color = gradient.Evaluate((float)x / (texture.width - 1)); + for (int y = 0; y < texture.height; y++) texture.SetPixel(x, y, color); + } + texture.Apply(); + } + + [MenuItem("Assets/AllIn1Shader Gradients/Remove All Gradient Textures")] + static void RemoveAllSubassets() + { + foreach(Object asset in Selection.GetFiltered(SelectionMode.Assets)) + { + string path = AssetDatabase.GetAssetPath(asset); + AssetDatabase.ImportAsset(path); + foreach(Object subAsset in AssetDatabase.LoadAllAssetRepresentationsAtPath(path)) + { + Object.DestroyImmediate(subAsset, true); + } + AssetDatabase.ImportAsset(path); + } + } + + class GradientRepresentation + { + public GradientMode mode; + public ColorKey[] colorKeys; + public AlphaKey[] alphaKeys; + + public GradientRepresentation() { } + + public GradientRepresentation(Gradient source) + { + FromGradient(source); + } + + private void FromGradient(Gradient source) + { + mode = source.mode; + colorKeys = source.colorKeys.Select(key => new ColorKey(key)).ToArray(); + alphaKeys = source.alphaKeys.Select(key => new AlphaKey(key)).ToArray(); + } + + private void ToGradient(Gradient gradient) + { + gradient.mode = mode; + gradient.colorKeys = colorKeys.Select(key => key.ToGradientKey()).ToArray(); + gradient.alphaKeys = alphaKeys.Select(key => key.ToGradientKey()).ToArray(); + } + + public Gradient ToGradient() + { + Gradient gradient = new Gradient(); + ToGradient(gradient); + return gradient; + } + + [Serializable] + public struct ColorKey + { + public Color color; + public float time; + + public ColorKey(GradientColorKey source) + { + color = default; + time = default; + FromGradientKey(source); + } + + public void FromGradientKey(GradientColorKey source) + { + color = source.color; + time = source.time; + } + + public GradientColorKey ToGradientKey() + { + GradientColorKey key; + key.color = color; + key.time = time; + return key; + } + } + + [Serializable] + public struct AlphaKey + { + public float alpha; + public float time; + + public AlphaKey(GradientAlphaKey source) + { + alpha = default; + time = default; + FromGradientKey(source); + } + + public void FromGradientKey(GradientAlphaKey source) + { + alpha = source.alpha; + time = source.time; + } + + public GradientAlphaKey ToGradientKey() + { + GradientAlphaKey key; + key.alpha = alpha; + key.time = time; + return key; + } + } + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderGradientDrawer.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderGradientDrawer.cs.meta new file mode 100644 index 0000000..6277919 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderGradientDrawer.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: c51263ea47edd3641a26e5f242925bcf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderGradientDrawer.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderImporter.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderImporter.cs new file mode 100644 index 0000000..881c607 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderImporter.cs @@ -0,0 +1,221 @@ +#if UNITY_EDITOR +using System; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace AllIn1SpriteShader +{ + [InitializeOnLoad] + public static class AllIn1ShaderImporter + { + public enum UnityVersion + { + NONE = 0, + UNITY_2019 = 1, + UNITY_2020 = 2, + UNITY_2021 = 3, + UNITY_2022 = 4, + UNITY_6 = 5, + } + + public enum RenderPipeline + { + NONE = -1, + BIRP = 0, + URP = 1, + HDRP = 2, + } + + + private const string SHADER_FOLDER_PATH = "../../Shaders/LitShaders"; + private const string FINAL_SHADERS_FOLDER_PATH = "../../Shaders"; + private const string SHADER_TEMPLATE_NAME = @"{0}_{1}.txt"; + + private const string SPRITE_LIT_SHADER_NAME = "AllIn1SpriteShaderLit"; + private const string SPRITE_LIT_TRANSPARENT_SHADER_NAME = "AllIn1SpriteShaderLitTransparent"; + + private const string PIPELINE_SUFFIX_URP_2019 = "BetterShader_URP2019"; + private const string PIPELINE_SUFFIX_HDRP_2019 = "BetterShader_HDRP2019"; + + private const string PIPELINE_SUFFIX_URP_2020 = "BetterShader_URP2020"; + private const string PIPELINE_SUFFIX_HDRP_2020 = "BetterShader_HDRP2020"; + + private const string PIPELINE_SUFFIX_URP_2021 = "BetterShader_URP2021"; + private const string PIPELINE_SUFFIX_HDRP_2021 = "BetterShader_HDRP2021"; + + private const string PIPELINE_SUFFIX_URP_2022 = "BetterShader_URP2022"; + private const string PIPELINE_SUFFIX_HDRP_2022 = "BetterShader_HDRP2022"; + + private const string PIPELINE_SUFFIX_URP_2023 = "BetterShader_URP2023"; + private const string PIPELINE_SUFFIX_HDRP_2023 = "BetterShader_HDRP2023"; + + private const string PIPELINE_SUFFIX_STANDARD = "BetterShader_Standard"; + + private const string LIT_SHADER_PIPELINE_KEY = "AllIn1SpriteShader_LitShader_RenderPipeline"; + private const string LIT_SHADER_UNITY_VERSION_KEY = "AllIn1SpriteShader_LitShader_UnityVersion"; + private const string LIT_SHADER_FIRST_TIME_PROJECT = "AllIn1SpriteShader_LitShader_FirstTimeProject"; + + static AllIn1ShaderImporter() + { + ConfigureShaders(); + } + + private static void ConfigureShaders() + { + RenderPipelineChecker.RefreshData(); + + UnityVersion unityVersion = GetUnityVersion(); + RenderPipeline renderPipeline = GetRenderPipeline(); + + RenderPipeline lastRenderPipeline = (RenderPipeline)SessionState.GetInt(LIT_SHADER_PIPELINE_KEY, -1); + UnityVersion lastUnityVersion = (UnityVersion)SessionState.GetInt(LIT_SHADER_UNITY_VERSION_KEY, 0); + int firstTimeProject = SessionState.GetInt(LIT_SHADER_FIRST_TIME_PROJECT, -1); + + if (lastRenderPipeline != renderPipeline || lastUnityVersion != unityVersion || firstTimeProject != 1) + { + SessionState.SetInt(LIT_SHADER_PIPELINE_KEY, (int)renderPipeline); + SessionState.SetInt(LIT_SHADER_UNITY_VERSION_KEY, (int)unityVersion); + SessionState.SetInt(LIT_SHADER_FIRST_TIME_PROJECT, 1); + + ConfigureShader(SPRITE_LIT_SHADER_NAME); + ConfigureShader(SPRITE_LIT_TRANSPARENT_SHADER_NAME); + } + } + + private static void ConfigureShader(string shaderName) + { + string pipelineSufix = string.Empty; + + UnityVersion unityVersion = GetUnityVersion(); + RenderPipeline renderPipeline = GetRenderPipeline(); + + if (renderPipeline == RenderPipeline.HDRP) + { + switch (unityVersion) + { + case UnityVersion.UNITY_2019: + pipelineSufix = PIPELINE_SUFFIX_HDRP_2019; + break; + case UnityVersion.UNITY_2020: + pipelineSufix = PIPELINE_SUFFIX_HDRP_2020; + break; + case UnityVersion.UNITY_2021: + pipelineSufix = PIPELINE_SUFFIX_HDRP_2021; + break; + case UnityVersion.UNITY_2022: + pipelineSufix = PIPELINE_SUFFIX_HDRP_2022; + break; + case UnityVersion.UNITY_6: + pipelineSufix = PIPELINE_SUFFIX_HDRP_2023; + break; + + } + } + else if (renderPipeline == RenderPipeline.URP) + { + switch (unityVersion) + { + case UnityVersion.UNITY_2019: + pipelineSufix = PIPELINE_SUFFIX_URP_2019; + break; + case UnityVersion.UNITY_2020: + pipelineSufix = PIPELINE_SUFFIX_URP_2020; + break; + case UnityVersion.UNITY_2021: + pipelineSufix = PIPELINE_SUFFIX_URP_2021; + break; + case UnityVersion.UNITY_2022: + pipelineSufix = PIPELINE_SUFFIX_URP_2022; + break; + case UnityVersion.UNITY_6: + pipelineSufix = PIPELINE_SUFFIX_URP_2023; + break; + } + } + else + { + pipelineSufix = PIPELINE_SUFFIX_STANDARD; + } + + string templateFileName = string.Format(SHADER_TEMPLATE_NAME, shaderName, pipelineSufix); + + string shaderTemplatePath = SHADER_FOLDER_PATH + "/" + templateFileName; + string finalShaderPath = FINAL_SHADERS_FOLDER_PATH + "/" + $"{shaderName}.shader"; + + try + { + var currentFileGUID = AssetDatabase.FindAssets($"t:Script {nameof(AllIn1ShaderImporter)}")[0]; + string currentFolder = Path.GetDirectoryName(AssetDatabase.GUIDToAssetPath(currentFileGUID)); + + string newShaderStr = File.ReadAllText(Path.Combine(currentFolder, shaderTemplatePath)); + newShaderStr = newShaderStr.Replace($"Shader \"AllIn1SpriteShader/{shaderName}_BetterShader\"", $"Shader \"AllIn1SpriteShader/{shaderName}\""); + + File.WriteAllText(Path.Combine(currentFolder, finalShaderPath), EditorUtils.UnifyEOL(newShaderStr)); + + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + catch (Exception e) + { + Debug.LogError("Shader not found: " + e); + } + } + + private static UnityVersion GetUnityVersion() + { + UnityVersion res = UnityVersion.NONE; + + string unityVersion = Application.unityVersion; + + if (unityVersion.Contains("2019")) + { + res = UnityVersion.UNITY_2019; + } + else if (unityVersion.Contains("2020")) + { + res = UnityVersion.UNITY_2020; + } + else if (unityVersion.Contains("2021")) + { + res = UnityVersion.UNITY_2021; + } + else if (unityVersion.Contains("2022")) + { + res = UnityVersion.UNITY_2022; + } + else if (unityVersion.Contains("6000")) + { + res = UnityVersion.UNITY_6; + } + + return res; + } + + private static RenderPipeline GetRenderPipeline() + { + RenderPipeline res = RenderPipeline.BIRP; + + if (RenderPipelineChecker.IsURP) + { + res = RenderPipeline.URP; + } + else if (RenderPipelineChecker.IsHDRP) + { + res = RenderPipeline.HDRP; + } + + return res; + } + + public static void ForceReimport() + { + SessionState.EraseInt(LIT_SHADER_PIPELINE_KEY); + SessionState.EraseInt(LIT_SHADER_UNITY_VERSION_KEY); + SessionState.EraseInt(LIT_SHADER_FIRST_TIME_PROJECT); + + ConfigureShaders(); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderImporter.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderImporter.cs.meta new file mode 100644 index 0000000..6c26ba9 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderImporter.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: aa9d501412652444c8b5b573248c31be +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderImporter.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderPropertyType.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderPropertyType.cs new file mode 100644 index 0000000..767b43b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderPropertyType.cs @@ -0,0 +1,12 @@ +namespace AllIn1SpriteShader +{ + public enum AllIn1ShaderPropertyType + { + Color, + Vector, + Float, + Range, + Texture, + Int, + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderPropertyType.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderPropertyType.cs.meta new file mode 100644 index 0000000..9ee9f74 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderPropertyType.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 292320b1088d1734184f5459f884be05 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderPropertyType.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderScriptEditor.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderScriptEditor.cs new file mode 100644 index 0000000..0293ebf --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderScriptEditor.cs @@ -0,0 +1,327 @@ +#if UNITY_EDITOR +using UnityEditor; +using UnityEngine; +using UnityEngine.UI; +using ShaderType = AllIn1SpriteShader.AllIn1Shader.ShaderTypes; + +namespace AllIn1SpriteShader +{ + [CustomEditor(typeof(AllIn1Shader)), CanEditMultipleObjects] + public class AllIn1ShaderScriptEditor : UnityEditor.Editor + { + private bool showUrpWarning = false; + private double warningTime = 0f; + private SerializedProperty m_NormalStrength, m_NormalSmoothing; + private Texture2D imageInspector; + + private enum ImageType + { + ShowImage, + HideInComponent, + HideEverywhere + } + private ImageType imageType; + + private void OnEnable() + { + m_NormalStrength = serializedObject.FindProperty("normalStrength"); + m_NormalSmoothing = serializedObject.FindProperty("normalSmoothing"); + } + + public override void OnInspectorGUI() + { + ChooseAndDisplayAssetImage(); + + AllIn1Shader myScript = (AllIn1Shader)target; + + SetCurrentShaderType(myScript); + + if (GUILayout.Button("Deactivate All Effects")) + { + for (int i = 0; i < targets.Length; i++) ((AllIn1Shader)targets[i]).ClearAllKeywords(); + AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Deactivated All Effects"); + } + + if (GUILayout.Button("New Clean Material")) + { + bool successOperation = true; + for (int i = 0; i < targets.Length; i++) + { + successOperation &= ((AllIn1Shader)targets[i]).TryCreateNew(); + } + if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Clean Material"); + } + + + if (GUILayout.Button("Create New Material With Same Properties (SEE DOC)")) + { + bool successOperation = true; + for (int i = 0; i < targets.Length; i++) + { + successOperation &= ((AllIn1Shader)targets[i]).MakeCopy(); + } + if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Copy Created"); + } + + if (GUILayout.Button("Save Material To Folder (SEE DOC)")) + { + bool successOperation = true; + for(int i = 0; i < targets.Length; i++) + { + successOperation &= ((AllIn1Shader) targets[i]).SaveMaterial(); + } + if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Material Saved"); + } + + if (GUILayout.Button("Apply Material To All Children")) + { + bool successOperation = true; + for(int i = 0; i < targets.Length; i++) + { + successOperation &= ((AllIn1Shader) targets[i]).ApplyMaterialToHierarchy(); + } + if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Material Applied To Children"); + else EditorUtility.DisplayDialog("No children found", "All In 1 Shader component couldn't find any children to this GameObject (" + targets[0].name + ")", "Ok"); + } + + if (myScript.currentShaderType != AllIn1Shader.ShaderTypes.Urp2dRenderer) + { + if (GUILayout.Button("Render Material To Image")) + { + bool successOperation = true; + for(int i = 0; i < targets.Length; i++) + { + successOperation &= ((AllIn1Shader) targets[i]).RenderToImage(); + } + if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Material Rendered To Image"); + } + } + + bool isUrp = false; + Shader temp = AllIn1ShaderWindow.FindShader("AllIn1Urp2dRenderer"); + if (temp != null) isUrp = true; + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Change Shader Variant:", GUILayout.MaxWidth(140)); + int previousShaderType = (int)myScript.currentShaderType; + myScript.currentShaderType = (AllIn1Shader.ShaderTypes)EditorGUILayout.EnumPopup(myScript.currentShaderType); + if (previousShaderType != (int)myScript.currentShaderType) + { + for (int i = 0; i < targets.Length; i++) ((AllIn1Shader)targets[i]).CheckIfValidTarget(); + if (myScript == null) return; + if (isUrp || myScript.currentShaderType != AllIn1Shader.ShaderTypes.Urp2dRenderer) + { + AllIn1ShaderWindow.SceneViewNotificationAndLog(myScript.gameObject.name + " shader variant has been changed to: " + myScript.currentShaderType); + myScript.SetSceneDirty(); + + Renderer sr = myScript.GetComponent(); + if (sr != null) + { + if (sr.sharedMaterial != null) + { + int renderingQueue = sr.sharedMaterial.renderQueue; + if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Default) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShader"); + else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.ScaledTime) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderScaledTime"); + else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.MaskedUI) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderUiMask"); + else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Urp2dRenderer) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1Urp2dRenderer"); + else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Lit) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderLit"); + else if(myScript.currentShaderType == AllIn1Shader.ShaderTypes.SRPBatcher) sr.sharedMaterial.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderSRPBatch"); + else SetCurrentShaderType(myScript); + sr.sharedMaterial.renderQueue = renderingQueue; + + if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Lit) + { + sr.sharedMaterial.SetFloat("_ZWrite", 1.0f); + sr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On; + sr.receiveShadows = true; + sr.sharedMaterial.renderQueue = 2000; + } + else + { + sr.sharedMaterial.SetFloat("_ZWrite", 0f); + sr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; + sr.receiveShadows = false; + sr.sharedMaterial.renderQueue = 3000; + } + } + } + else + { + Graphic img = myScript.GetComponent(); + if (img != null && img.material != null) + { + int renderingQueue = img.material.renderQueue; + if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Default) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShader"); + else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.ScaledTime) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderScaledTime"); + else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.MaskedUI) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderUiMask"); + else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Urp2dRenderer) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1Urp2dRenderer"); + else if (myScript.currentShaderType == AllIn1Shader.ShaderTypes.Lit) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderLit"); + else if(myScript.currentShaderType == AllIn1Shader.ShaderTypes.SRPBatcher) img.material.shader = AllIn1ShaderWindow.FindShader("AllIn1SpriteShaderSRPBatch"); + else SetCurrentShaderType(myScript); + img.material.renderQueue = renderingQueue; + } + } + } + else if(!isUrp && myScript.currentShaderType == AllIn1Shader.ShaderTypes.Urp2dRenderer) + { + myScript.currentShaderType = (AllIn1Shader.ShaderTypes) previousShaderType; + showUrpWarning = true; + warningTime = EditorApplication.timeSinceStartup + 5; + } + } + } + EditorGUILayout.EndHorizontal(); + + if (warningTime < EditorApplication.timeSinceStartup) showUrpWarning = false; + if (isUrp) showUrpWarning = false; + if (showUrpWarning) EditorGUILayout.HelpBox( + "You can't set the URP 2D Renderer variant since you didn't import the URP package available in the asset root folder (SEE DOCUMENTATION)", + MessageType.Error, + true); + + if ((isUrp && myScript.currentShaderType == AllIn1Shader.ShaderTypes.Urp2dRenderer) || myScript.currentShaderType == AllIn1Shader.ShaderTypes.Lit) + { + EditorGUILayout.Space(); + DrawLine(Color.grey, 1, 3); + EditorGUILayout.Space(); + + if (GUILayout.Button("Create And Add Normal Map")) + { + for (int i = 0; i < targets.Length; i++) ((AllIn1Shader)targets[i]).CreateAndAssignNormalMap(); + AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Creating Normal Map"); + + } + serializedObject.Update(); + EditorGUILayout.PropertyField(m_NormalStrength, new GUIContent("Normal Strength"), GUILayout.Height(20)); + EditorGUILayout.PropertyField(m_NormalSmoothing, new GUIContent("Normal Blur"), GUILayout.Height(20)); + if (myScript.computingNormal) + { + EditorGUILayout.LabelField("Normal Map is currently being created, be patient", EditorStyles.boldLabel, GUILayout.Height(40)); + } + serializedObject.ApplyModifiedProperties(); + + EditorGUILayout.Space(); + } + + DrawLine(Color.grey, 1, 3); + EditorGUILayout.Space(); + + if (GUILayout.Button("Sprite Atlas Auto Setup")) + { + bool successOperation = true; + for(int i = 0; i < targets.Length; i++) + { + successOperation &= ((AllIn1Shader) targets[i]).ToggleSetAtlasUvs(true); + } + if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Sprite Atlas Auto Setup"); + } + if (GUILayout.Button("Remove Sprite Atlas Configuration")) + { + bool successOperation = true; + for(int i = 0; i < targets.Length; i++) + { + successOperation &= ((AllIn1Shader) targets[i]).ToggleSetAtlasUvs(false); + } + if(successOperation) AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Remove Sprite Atlas Configuration"); + } + +#if LETAI_TRUESHADOW + if (myScript.GetComponent() && !myScript.GetComponent()) + { + EditorGUILayout.Space(); + DrawLine(Color.grey, 1, 3); + if (GUILayout.Button("Add True Shadow Compatibility")) + { + myScript.gameObject.AddComponent(); + myScript.SetSceneDirty(); + } + } +#endif + + EditorGUILayout.Space(); + DrawLine(Color.grey, 1, 3); + + if(GUILayout.Button("Remove Component")) + { + for(int i = targets.Length - 1; i >= 0; i--) + { + DestroyImmediate(targets[i] as AllIn1Shader); + ((AllIn1Shader)targets[i]).SetSceneDirty(); + } + AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Component Removed"); + } + + if (GUILayout.Button("REMOVE COMPONENT AND MATERIAL")) + { + for (int i = 0; i < targets.Length; i++) + { + ((AllIn1Shader)targets[i]).CleanMaterial(); + } + for (int i = targets.Length - 1; i >= 0; i--) + { + DestroyImmediate(targets[i] as AllIn1Shader); + } + AllIn1ShaderWindow.ShowSceneViewNotification("AllIn1SpriteShader: Component And Material Removed"); + } + } + + private void ChooseAndDisplayAssetImage() + { + if(!EditorPrefs.HasKey("allIn1ImageConfig")) + { + EditorPrefs.SetInt("allIn1ImageConfig", (int) ImageType.ShowImage); + } + + imageType = (ImageType) EditorPrefs.GetInt("allIn1ImageConfig"); + switch(imageType) + { + case ImageType.ShowImage: + case ImageType.HideInComponent: + if(imageInspector == null) imageInspector = AllIn1ShaderWindow.GetInspectorImage(); + break; + } + + if(imageInspector && imageType != ImageType.HideInComponent && imageType != ImageType.HideEverywhere && imageInspector) + { + Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(40)); + GUI.DrawTexture(rect, imageInspector, ScaleMode.ScaleToFit, true); + } + } + + private void SetCurrentShaderType(AllIn1Shader myScript) + { + string shaderName = ""; + Renderer sr = myScript.GetComponent(); + if (sr != null) + { + if(sr.sharedMaterial == null) return; + shaderName = sr.sharedMaterial.shader.name; + } + else + { + Graphic img = myScript.GetComponent(); + if(img.material == null) return; + if (img != null) shaderName = img.material.shader.name; + } + shaderName = shaderName.Replace("AllIn1SpriteShader/", ""); + + if (shaderName.Equals("AllIn1SpriteShader")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.Default; + else if (shaderName.Equals("AllIn1SpriteShaderScaledTime")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.ScaledTime; + else if (shaderName.Equals("AllIn1SpriteShaderUiMask")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.MaskedUI; + else if (shaderName.Equals("AllIn1Urp2dRenderer")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.Urp2dRenderer; + else if(shaderName.Equals("AllIn1SpriteShaderLit")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.Lit; + else if(shaderName.Equals("AllIn1SpriteShaderSRPBatch")) myScript.currentShaderType = AllIn1Shader.ShaderTypes.SRPBatcher; + } + + private void DrawLine(Color color, int thickness = 2, int padding = 10) + { + Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness)); + r.height = thickness; + r.y += (padding / 2); + r.x -= 2; + r.width += 6; + EditorGUI.DrawRect(r, color); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderScriptEditor.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderScriptEditor.cs.meta new file mode 100644 index 0000000..f7e77d3 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderScriptEditor.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 78232fc1cf0e9c445a36b7bf7fc49fdb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1ShaderScriptEditor.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderLitMaterialInspector.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderLitMaterialInspector.cs new file mode 100644 index 0000000..f000ec5 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderLitMaterialInspector.cs @@ -0,0 +1,850 @@ +#if UNITY_EDITOR +using AllIn1SpriteShader; +using System.Linq; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; +using UnityEngine.Rendering; + +namespace AllIn1SpriteShader +{ + [CanEditMultipleObjects] + public class AllIn1SpriteShaderLitMaterialInspector : ShaderGUI + { + private Material targetMat; + private BlendMode srcMode, dstMode; + private CompareFunction zTestMode = CompareFunction.LessEqual; + private CullMode cullMode; + + private GUIStyle propertiesStyle, bigLabelStyle, smallLabelStyle, toggleButtonStyle; + private const int bigFontSize = 16, smallFontSize = 11; + private string[] oldKeyWords; + private int effectCount = 1; + private Material originalMaterialCopy; + private MaterialEditor matEditor; + private MaterialProperty[] matProperties; + private uint[] materialDrawers = new uint[] { 1, 2, 4 }; + bool[] currEnabledDrawers; + private const uint advancedConfigDrawer = 0; + private const uint colorFxShapeDrawer = 1; + private const uint uvFxShapeDrawer = 2; + + + + public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) + { + matEditor = materialEditor; + matProperties = properties; + targetMat = materialEditor.target as Material; + effectCount = 1; + oldKeyWords = targetMat.shaderKeywords; + propertiesStyle = new GUIStyle(EditorStyles.helpBox); + propertiesStyle.margin = new RectOffset(0, 0, 0, 0); + bigLabelStyle = new GUIStyle(EditorStyles.boldLabel); + bigLabelStyle.fontSize = bigFontSize; + smallLabelStyle = new GUIStyle(EditorStyles.boldLabel); + smallLabelStyle.fontSize = smallFontSize; + toggleButtonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleCenter, richText = true }; + currEnabledDrawers = new bool[materialDrawers.Length]; + uint iniDrawers = (uint)ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue; + for(int i = 0; i < materialDrawers.Length; i++) currEnabledDrawers[i] = (materialDrawers[i] & iniDrawers) > 0; + + GUILayout.Label("General Properties", bigLabelStyle); + DrawProperty(0); + DrawProperty(172); + + DrawProperty(1); + //DrawProperty(2); + DrawProperty(70); + + currEnabledDrawers[advancedConfigDrawer] = GUILayout.Toggle(currEnabledDrawers[advancedConfigDrawer], new GUIContent("Show Advanced Configuration"), toggleButtonStyle); + if(currEnabledDrawers[advancedConfigDrawer]) + { + + EditorGUILayout.BeginVertical(propertiesStyle); + Culling(); + DrawLine(Color.grey, 1, 3); + ZTest(); + DrawLine(Color.grey, 1, 3); + ZWrite(); + DrawLine(Color.grey, 1, 3); + Billboard("Billboard active", "BILBOARD_ON"); + DrawLine(Color.grey, 1, 3); + SpriteAtlas("Sprite inside an atlas?", "ATLAS_ON"); + DrawLine(Color.grey, 1, 3); + materialEditor.EnableInstancingField(); + DrawLine(Color.grey, 1, 3); + materialEditor.RenderQueueField(); + EditorGUILayout.EndVertical(); + } + + EditorGUILayout.Separator(); + DrawLine(Color.grey, 1, 3); + GUILayout.Label("Light Effect", bigLabelStyle); + GenericEffect("Normal Map", "NORMALMAP_ON", 189, 190); + + EditorGUILayout.Separator(); + DrawLine(Color.grey, 1, 3); + GUILayout.Label("Color Effects", bigLabelStyle); + + currEnabledDrawers[colorFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[colorFxShapeDrawer], new GUIContent("Show Color Effects"), toggleButtonStyle); + if(currEnabledDrawers[colorFxShapeDrawer]) + { + Glow("Glow", "GLOW_ON"); + GenericEffect("Fade", "FADE_ON", 7, 13, extraProperties: new int[] { 173, 174 } ); + Outline("Outline", "OUTBASE_ON"); + GenericEffect("Alpha Outline", "ALPHAOUTLINE_ON", 26, 30, true, "A more performant but less flexible outline"); + InnerOutline("Inner Outline", "INNEROUTLINE_ON", 66, 69); + Gradient("Gradient & Radial Gradient", "GRADIENT_ON"); + GenericEffect("Color Swap", "COLORSWAP_ON", 36, 42, true, "You will need a mask texture (see Documentation)", new int[] { 154 }); + GenericEffect("Hue Shift", "HSV_ON", 43, 45); + ColorChange("Change 1 Color", "CHANGECOLOR_ON"); + ColorRamp("Color Ramp", "COLORRAMP_ON"); + GenericEffect("Hit Effect", "HITEFFECT_ON", 46, 48); + GenericEffect("Negative", "NEGATIVE_ON", 49, 49); + GenericEffect("Pixelate", "PIXELATE_ON", 50, 50, true, "Looks bad with distorition effects"); + GreyScale("GreyScale", "GREYSCALE_ON"); + Posterize("Posterize", "POSTERIZE_ON"); + Blur("Blur", "BLUR_ON"); + GenericEffect("Motion Blur", "MOTIONBLUR_ON", 62, 63); + GenericEffect("Ghost", "GHOST_ON", 64, 65, true, "This effect will not affect the outline", new int[] { 157 }); + GenericEffect("Hologram", "HOLOGRAM_ON", 73, 77, true, null, new int[] { 140, 158 }); + GenericEffect("Chromatic Aberration", "CHROMABERR_ON", 78, 79); + GenericEffect("Glitch", "GLITCH_ON", 80, 80, true, null, new int[] { 139, 180 }); + GenericEffect("Flicker", "FLICKER_ON", 81, 83); + GenericEffect("Shadow", "SHADOW_ON", 84, 87); + GenericEffect("Shine", "SHINE_ON", 133, 138); + GenericEffect("Contrast & Brightness", "CONTRAST_ON", 152, 153); + Overlay("Overlay Texture", "OVERLAY_ON"); + } + + DrawLine(Color.grey, 1, 3); + GUILayout.Label("UV Effects", bigLabelStyle); + + currEnabledDrawers[uvFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[uvFxShapeDrawer], new GUIContent("Show UV Effects"), toggleButtonStyle); + if(currEnabledDrawers[uvFxShapeDrawer]) + { + GenericEffect("Hand Drawn", "DOODLE_ON", 88, 89); + Grass("Grass Movement / Wind", "WIND_ON"); + GenericEffect("Wave", "WAVEUV_ON", 94, 98); + GenericEffect("Round Wave", "ROUNDWAVEUV_ON", 127, 128); + GenericEffect("Rect Size (Enable wireframe to see result)", "RECTSIZE_ON", 99, 99, true, "Only on single sprites spritesheets NOT supported"); + GenericEffect("Offset", "OFFSETUV_ON", 100, 101); + GenericEffect("Clipping / Fill Amount", "CLIPPING_ON", 102, 105); + GenericEffect("Radial Clipping / Radial Fill", "RADIALCLIPPING_ON", 164, 166); + GenericEffect("Texture Scroll", "TEXTURESCROLL_ON", 106, 107, true, "Set Texture Wrap Mode to Repeat"); + GenericEffect("Zoom", "ZOOMUV_ON", 108, 108); + GenericEffect("Distortion", "DISTORT_ON", 109, 112, extraProperties: new int[] { 177 } ); + GenericEffect("Warp Distortion", "WARP_ON", 167, 169); + GenericEffect("Twist", "TWISTUV_ON", 113, 116); + GenericEffect("Rotate", "ROTATEUV_ON", 117, 117, true, "_Tip_ Use Clipping effect to avoid possible undesired parts"); + GenericEffect("Polar Coordinates (Tile texture for good results)", "POLARUV_ON", -1, -1); + GenericEffect("Fish Eye", "FISHEYE_ON", 118, 118); + GenericEffect("Pinch", "PINCH_ON", 119, 119); + GenericEffect("Shake", "SHAKEUV_ON", 120, 122); + } + + SetAndSaveEnabledDrawers(iniDrawers); + } + + private void SetAndSaveEnabledDrawers(uint iniDrawers) + { + uint currDrawers = 0; + for(int i = 0; i < currEnabledDrawers.Length; i++) + { + if(currEnabledDrawers[i]) currDrawers |= materialDrawers[i]; + } + + if(iniDrawers != currDrawers) ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue = currDrawers; + } + + private void Blending() + { + MaterialProperty srcM = ShaderGUI.FindProperty("_MySrcMode", matProperties); + MaterialProperty dstM = ShaderGUI.FindProperty("_MyDstMode", matProperties); + if(srcM.floatValue == 0 && dstM.floatValue == 0) + { + srcM.floatValue = 5; + dstM.floatValue = 10; + } + + GUILayout.Label("This doesn't make much sense in a lit shader", smallLabelStyle); + if(GUILayout.Button("Back To Default Blending")) + { + srcM.floatValue = 5; + dstM.floatValue = 10; + targetMat.DisableKeyword("PREMULTIPLYALPHA_ON"); + } + + srcMode = (BlendMode)srcM.floatValue; + dstMode = (BlendMode)dstM.floatValue; + srcMode = (BlendMode)EditorGUILayout.EnumPopup("SrcMode", srcMode); + dstMode = (BlendMode)EditorGUILayout.EnumPopup("DstMode", dstMode); + srcM.floatValue = (float)(srcMode); + dstM.floatValue = (float)(dstMode); + + bool ini = oldKeyWords.Contains("PREMULTIPLYALPHA_ON"); + bool toggle = EditorGUILayout.Toggle("Premultiply Alpha?", ini); + if(ini != toggle) Save(); + if(toggle) targetMat.EnableKeyword("PREMULTIPLYALPHA_ON"); + else targetMat.DisableKeyword("PREMULTIPLYALPHA_ON"); + } + + private void Billboard(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = inspector; + toggle = GUILayout.Toggle(toggle, effectNameLabel); + + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + GUILayout.Label("Don't use this feature on UI elements!", smallLabelStyle); + DrawProperty(129, true); + MaterialProperty billboardY = matProperties[129]; + if(billboardY.floatValue == 1) targetMat.EnableKeyword("BILBOARDY_ON"); + else targetMat.DisableKeyword("BILBOARDY_ON"); + } + else targetMat.DisableKeyword(keyword); + } + + private void ZWrite() + { + MaterialProperty zWrite = ShaderGUI.FindProperty("_ZWrite", matProperties); + bool toggle = zWrite.floatValue > 0.9f ? true : false; + EditorGUILayout.BeginHorizontal(); + { + float tempValue = zWrite.floatValue; + toggle = GUILayout.Toggle(toggle, new GUIContent("Enable Z Write")); + if(toggle) zWrite.floatValue = 1.0f; + else zWrite.floatValue = 0.0f; + if(tempValue != zWrite.floatValue && !Application.isPlaying) Save(); + } + EditorGUILayout.EndHorizontal(); + } + + private void ZTest() + { + MaterialProperty zTestM = ShaderGUI.FindProperty("_ZTestMode", matProperties); + float tempValue = zTestM.floatValue; + zTestMode = (UnityEngine.Rendering.CompareFunction)zTestM.floatValue; + zTestMode = (UnityEngine.Rendering.CompareFunction)EditorGUILayout.EnumPopup("Z TestMode", zTestMode); + zTestM.floatValue = (float)(zTestMode); + if(tempValue != zTestM.floatValue && !Application.isPlaying) Save(); + } + + private void Culling() + { + MaterialProperty cullO = ShaderGUI.FindProperty("_CullingOption", matProperties); + ; + float tempValue = cullO.floatValue; + cullMode = (UnityEngine.Rendering.CullMode)cullO.floatValue; + cullMode = (UnityEngine.Rendering.CullMode)EditorGUILayout.EnumPopup("Culling Mode", cullMode); + cullO.floatValue = (float)(cullMode); + if(tempValue != cullO.floatValue && !Application.isPlaying) Save(); + } + + private void SpriteAtlas(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + toggle = GUILayout.Toggle(toggle, inspector); + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + EditorGUILayout.BeginVertical(propertiesStyle); + { + GUILayout.Label("Make sure SpriteAtlasUV component is added \n " + + "*Check documentation if unsure what this does or how it works", smallLabelStyle); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + } + + private void Outline(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + ".Outline"; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("OUTBASE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(14); + DrawProperty(15); + DrawProperty(16); + DrawEffectSubKeywordToggle("Outline High Resolution?", "OUTBASE8DIR_ON"); + + DrawLine(Color.grey, 1, 3); + bool outlinePixelPerf = DrawEffectSubKeywordToggle("Outline is Pixel Perfect?", "OUTBASEPIXELPERF_ON"); + if(outlinePixelPerf) DrawProperty(18); + else DrawProperty(17); + + DrawLine(Color.grey, 1, 3); + bool outlineTexture = DrawEffectSubKeywordToggle("Outline uses texture?", "OUTTEX_ON"); + if(outlineTexture) + { + DrawProperty(19); + DrawProperty(175); + DrawProperty(20); + DrawProperty(21); + } + + DrawLine(Color.grey, 1, 3); + bool outlineDistort = DrawEffectSubKeywordToggle("Outline uses distortion?", "OUTDIST_ON"); + if(outlineDistort) + { + DrawProperty(22); + DrawProperty(176); + DrawProperty(23); + DrawProperty(24); + DrawProperty(25); + } + + DrawLine(Color.grey, 1, 3); + DrawEffectSubKeywordToggle("Only render outline?", "ONLYOUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("OUTBASE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void GenericEffect(string inspector, string keyword, int first, int last, bool effectCounter = true, string preMessage = null, int[] extraProperties = null, bool boldToggleLetters = true) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + if(effectCounter) + { + effectNameLabel.text = effectCount + "." + inspector; + effectCount++; + } + else effectNameLabel.text = inspector; + + if(boldToggleLetters) toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + else toggle = GUILayout.Toggle(toggle, effectNameLabel); + + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + if(first > 0) + { + EditorGUILayout.BeginVertical(propertiesStyle); + { + if(preMessage != null) GUILayout.Label(preMessage, smallLabelStyle); + for(int i = first; i <= last; i++) DrawProperty(i); + if(extraProperties != null) + foreach(int i in extraProperties) + DrawProperty(i); + } + EditorGUILayout.EndVertical(); + } + } + else targetMat.DisableKeyword(keyword); + + if(boldToggleLetters) EditorGUILayout.EndToggleGroup(); + } + + private void Glow(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("GLOW_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool useGlowTex = DrawEffectSubKeywordToggle("Use Glow Texture?", "GLOWTEX_ON"); + if(useGlowTex) DrawProperty(6); + + DrawProperty(3); + DrawProperty(4); + DrawProperty(5, true); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("GLOW_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void ColorRamp(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("COLORRAMP_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool useEditableGradient = false; + if(AssetDatabase.Contains(targetMat)) + { + useEditableGradient = oldKeyWords.Contains("GRADIENTCOLORRAMP_ON"); + bool gradientTex = useEditableGradient; + gradientTex = GUILayout.Toggle(gradientTex, new GUIContent("Use Editable Gradient?")); + if(useEditableGradient != gradientTex) + { + Save(); + if(gradientTex) + { + useEditableGradient = true; + targetMat.EnableKeyword("GRADIENTCOLORRAMP_ON"); + } + else targetMat.DisableKeyword("GRADIENTCOLORRAMP_ON"); + } + + if(useEditableGradient) matEditor.ShaderProperty(matProperties[159], matProperties[159].displayName); + } + else GUILayout.Label("*Save to folder to allow for dynamic Gradient property", smallLabelStyle); + + if(!useEditableGradient) DrawProperty(51); + + DrawProperty(52); + DrawProperty(53, true); + MaterialProperty colorRampOut = matProperties[53]; + if(colorRampOut.floatValue == 1) targetMat.EnableKeyword("COLORRAMPOUTLINE_ON"); + else targetMat.DisableKeyword("COLORRAMPOUTLINE_ON"); + DrawProperty(155); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("COLORRAMP_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void ColorChange(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("CHANGECOLOR_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + for(int i = 123; i < 127; i++) DrawProperty(i); + + DrawLine(Color.grey, 1, 3); + ini = oldKeyWords.Contains("CHANGECOLOR2_ON"); + bool toggle2 = ini; + toggle2 = EditorGUILayout.Toggle("Use Color 2", ini); + if(ini != toggle2) Save(); + if(toggle2) + { + targetMat.EnableKeyword("CHANGECOLOR2_ON"); + for(int i = 146; i < 149; i++) DrawProperty(i); + } + else targetMat.DisableKeyword("CHANGECOLOR2_ON"); + + DrawLine(Color.grey, 1, 3); + ini = oldKeyWords.Contains("CHANGECOLOR3_ON"); + toggle2 = ini; + toggle2 = EditorGUILayout.Toggle("Use Color 3", toggle2); + if(ini != toggle2) Save(); + if(toggle2) + { + targetMat.EnableKeyword("CHANGECOLOR3_ON"); + for(int i = 149; i < 152; i++) DrawProperty(i); + } + else targetMat.DisableKeyword("CHANGECOLOR3_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("CHANGECOLOR_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void GreyScale(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("GREYSCALE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(54); + DrawProperty(56); + DrawProperty(55, true); + MaterialProperty greyScaleOut = matProperties[55]; + if(greyScaleOut.floatValue == 1) targetMat.EnableKeyword("GREYSCALEOUTLINE_ON"); + else targetMat.DisableKeyword("GREYSCALEOUTLINE_ON"); + DrawProperty(156); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("GREYSCALE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Posterize(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("POSTERIZE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(57); + DrawProperty(58); + DrawProperty(59, true); + MaterialProperty posterizeOut = matProperties[59]; + if(posterizeOut.floatValue == 1) targetMat.EnableKeyword("POSTERIZEOUTLINE_ON"); + else targetMat.DisableKeyword("POSTERIZEOUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("POSTERIZE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Blur(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("BLUR_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + GUILayout.Label("This effect will not affect the outline", smallLabelStyle); + DrawProperty(60); + DrawProperty(61, true); + MaterialProperty blurIsHd = matProperties[61]; + if(blurIsHd.floatValue == 1) targetMat.EnableKeyword("BLURISHD_ON"); + else targetMat.DisableKeyword("BLURISHD_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("BLUR_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Grass(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("WIND_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(90); + DrawProperty(91); + DrawProperty(145); + DrawProperty(92); + DrawProperty(93, true); + MaterialProperty grassManual = matProperties[92]; + if(grassManual.floatValue == 1) targetMat.EnableKeyword("MANUALWIND_ON"); + else targetMat.DisableKeyword("MANUALWIND_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("WIND_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void InnerOutline(string inspector, string keyword, int first, int last) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + if(first > 0) + { + EditorGUILayout.BeginVertical(propertiesStyle); + { + for(int i = first; i <= last; i++) DrawProperty(i); + + EditorGUILayout.Separator(); + DrawProperty(72, true); + MaterialProperty onlyInOutline = matProperties[72]; + if(onlyInOutline.floatValue == 1) targetMat.EnableKeyword("ONLYINNEROUTLINE_ON"); + else targetMat.DisableKeyword("ONLYINNEROUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void Gradient(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(143, true); + MaterialProperty gradIsRadial = matProperties[143]; + if(gradIsRadial.floatValue == 1) + { + targetMat.EnableKeyword("RADIALGRADIENT_ON"); + DrawProperty(31); + DrawProperty(32); + DrawProperty(34); + DrawProperty(141); + } + else + { + targetMat.DisableKeyword("RADIALGRADIENT_ON"); + bool simpleGradient = oldKeyWords.Contains("GRADIENT2COL_ON"); + bool simpleGradToggle = EditorGUILayout.Toggle("2 Color Gradient?", simpleGradient); + if(simpleGradient && !simpleGradToggle) targetMat.DisableKeyword("GRADIENT2COL_ON"); + else if(!simpleGradient && simpleGradToggle) targetMat.EnableKeyword("GRADIENT2COL_ON"); + DrawProperty(31); + DrawProperty(32); + if(!simpleGradToggle) DrawProperty(33); + DrawProperty(34); + if(!simpleGradToggle) DrawProperty(35); + if(!simpleGradToggle) DrawProperty(141); + DrawProperty(142); + } + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void Overlay(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool multModeOn = oldKeyWords.Contains("OVERLAYMULT_ON"); + bool isMultMode = multModeOn; + isMultMode = GUILayout.Toggle(isMultMode, new GUIContent("Is overlay multiplicative?")); + if(multModeOn != isMultMode) + { + Save(); + if(isMultMode) + { + multModeOn = true; + targetMat.EnableKeyword("OVERLAYMULT_ON"); + } + else targetMat.DisableKeyword("OVERLAYMULT_ON"); + } + + if(multModeOn) GUILayout.Label("Overlay is set to multiplicative mode", smallLabelStyle); + else GUILayout.Label("Overlay is set to additive mode", smallLabelStyle); + + + DrawProperty(160); + DrawProperty(178); + DrawProperty(161); + DrawProperty(162); + DrawProperty(163); + + for (int i = 170; i <= 171; i++) + { + DrawProperty(i); + } + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void DrawProperty(int index, bool noReset = false) + { + MaterialProperty targetProperty = matProperties[index]; + + EditorGUILayout.BeginHorizontal(); + { + GUIContent propertyLabel = new GUIContent(); + propertyLabel.text = targetProperty.displayName; + propertyLabel.tooltip = targetProperty.name + " (C#)"; + + matEditor.ShaderProperty(targetProperty, propertyLabel); + + if(!noReset) + { + GUIContent resetButtonLabel = new GUIContent(); + resetButtonLabel.text = "R"; + resetButtonLabel.tooltip = "Resets to default value"; + if(GUILayout.Button(resetButtonLabel, GUILayout.Width(20))) ResetProperty(targetProperty); + } + } + EditorGUILayout.EndHorizontal(); + } + + private void ResetProperty(MaterialProperty targetProperty) + { + AllIn1ShaderPropertyType shaderProperty = EditorUtils.GetShaderTypeByMaterialProperty(targetProperty); + + if(originalMaterialCopy == null) originalMaterialCopy = new Material(targetMat.shader); + if(shaderProperty == AllIn1ShaderPropertyType.Float || shaderProperty == AllIn1ShaderPropertyType.Range) + { + targetProperty.floatValue = originalMaterialCopy.GetFloat(targetProperty.name); + } + else if(shaderProperty == AllIn1ShaderPropertyType.Vector) + { + targetProperty.vectorValue = originalMaterialCopy.GetVector(targetProperty.name); + } + else if(shaderProperty == AllIn1ShaderPropertyType.Color) + { + targetProperty.colorValue = originalMaterialCopy.GetColor(targetProperty.name); + } + else if(shaderProperty == AllIn1ShaderPropertyType.Texture) + { + targetProperty.textureValue = originalMaterialCopy.GetTexture(targetProperty.name); + } + } + + private bool DrawEffectSubKeywordToggle(string inspector, string keyword, bool setCustomConfigAfter = false) + { + GUIContent propertyLabel = new GUIContent(); + propertyLabel.text = inspector; + propertyLabel.tooltip = keyword + " (C#)"; + + bool ini = oldKeyWords.Contains(keyword); + bool toggle = ini; + toggle = GUILayout.Toggle(toggle, propertyLabel); + if(ini != toggle) + { + if(toggle) targetMat.EnableKeyword(keyword); + else targetMat.DisableKeyword(keyword); + } + + return toggle; + } + + private void Save() + { + if(!Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + EditorUtility.SetDirty(targetMat); + } + + private void DrawLine(Color color, int thickness = 2, int padding = 10) + { + Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness)); + r.height = thickness; + r.y += (padding / 2); + r.x -= 2; + r.width += 6; + EditorGUI.DrawRect(r, color); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderLitMaterialInspector.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderLitMaterialInspector.cs.meta new file mode 100644 index 0000000..ca24a8e --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderLitMaterialInspector.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 58a451704eab27348bd5177152dc656f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderLitMaterialInspector.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderMaterialInspector.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderMaterialInspector.cs new file mode 100644 index 0000000..b5ded23 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderMaterialInspector.cs @@ -0,0 +1,884 @@ +#if UNITY_EDITOR +using System.Linq; +using AllIn1SpriteShader; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; +using UnityEngine.Rendering; + +namespace AllIn1SpriteShader +{ + [CanEditMultipleObjects] + public class AllIn1SpriteShaderMaterialInspector : ShaderGUI + { + private Material targetMat; + private BlendMode srcMode, dstMode; + private CompareFunction zTestMode = CompareFunction.LessEqual; + private CullMode cullMode; + + private GUIStyle propertiesStyle, bigLabelStyle, smallLabelStyle, toggleButtonStyle; + private const int bigFontSize = 16, smallFontSize = 11; + private string[] oldKeyWords; + private int effectCount = 1; + private Material originalMaterialCopy; + private MaterialEditor matEditor; + private MaterialProperty[] matProperties; + private uint[] materialDrawers = new uint[] { 1, 2, 4 }; + bool[] currEnabledDrawers; + private const uint advancedConfigDrawer = 0; + private const uint colorFxShapeDrawer = 1; + private const uint uvFxShapeDrawer = 2; + + public bool IsSRPShader() + { + bool res = false; + if(targetMat != null) + { + res = targetMat.shader.name == "AllIn1SpriteShader/AllIn1SpriteShaderSRPBatch"; + } + + return res; + } + + public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) + { + matEditor = materialEditor; + matProperties = properties; + targetMat = materialEditor.target as Material; + effectCount = 1; + oldKeyWords = targetMat.shaderKeywords; + propertiesStyle = new GUIStyle(EditorStyles.helpBox); + propertiesStyle.margin = new RectOffset(0, 0, 0, 0); + bigLabelStyle = new GUIStyle(EditorStyles.boldLabel); + bigLabelStyle.fontSize = bigFontSize; + smallLabelStyle = new GUIStyle(EditorStyles.boldLabel); + smallLabelStyle.fontSize = smallFontSize; + toggleButtonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleCenter, richText = true }; + currEnabledDrawers = new bool[materialDrawers.Length]; + bool isShaderSRP = IsSRPShader(); + + uint iniDrawers = (uint)ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue; + for(int i = 0; i < materialDrawers.Length; i++) currEnabledDrawers[i] = (materialDrawers[i] & iniDrawers) > 0; + + GUILayout.Label("General Properties", bigLabelStyle); + DrawProperty(0); + if (isShaderSRP) + { + DrawProperty(172); + } + + DrawProperty(1); + DrawProperty(2); + + + currEnabledDrawers[advancedConfigDrawer] = GUILayout.Toggle(currEnabledDrawers[advancedConfigDrawer], new GUIContent("Show Advanced Configuration"), toggleButtonStyle); + if(currEnabledDrawers[advancedConfigDrawer]) + { + + EditorGUILayout.BeginVertical(propertiesStyle); + Blending(); + DrawLine(Color.grey, 1, 3); + Culling(); + DrawLine(Color.grey, 1, 3); + ZTest(); + DrawLine(Color.grey, 1, 3); + ZWrite(); + DrawLine(Color.grey, 1, 3); + GenericEffect("Unity Fog", "FOG_ON", -1, -1, false, boldToggleLetters: false); + DrawLine(Color.grey, 1, 3); + Billboard("Billboard active", "BILBOARD_ON"); + DrawLine(Color.grey, 1, 3); + SpriteAtlas("Sprite inside an atlas?", "ATLAS_ON"); + DrawLine(Color.grey, 1, 3); + materialEditor.EnableInstancingField(); + DrawLine(Color.grey, 1, 3); + materialEditor.RenderQueueField(); + EditorGUILayout.EndVertical(); + } + + EditorGUILayout.Separator(); + DrawLine(Color.grey, 1, 3); + GUILayout.Label("Color Effects", bigLabelStyle); + + currEnabledDrawers[colorFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[colorFxShapeDrawer], new GUIContent("Show Color Effects"), toggleButtonStyle); + if(currEnabledDrawers[colorFxShapeDrawer]) + { + Glow("Glow", "GLOW_ON"); + if (isShaderSRP) + { + GenericEffect("Fade", "FADE_ON", 7, 13, true, null, new int[] { 173, 174 }); + } + else + { + GenericEffect("Fade", "FADE_ON", 7, 13, true); + } + + Outline("Outline", "OUTBASE_ON", isShaderSRP); + GenericEffect("Alpha Outline", "ALPHAOUTLINE_ON", 26, 30, true, "A more performant but less flexible outline"); + InnerOutline("Inner Outline", "INNEROUTLINE_ON", 66, 69); + Gradient("Gradient & Radial Gradient", "GRADIENT_ON"); + GenericEffect("Color Swap", "COLORSWAP_ON", 36, 42, true, "You will need a mask texture (see Documentation)", new int[] { 154 }); + GenericEffect("Hue Shift", "HSV_ON", 43, 45); + ColorChange("Change 1 Color", "CHANGECOLOR_ON"); + ColorRamp("Color Ramp", "COLORRAMP_ON"); + GenericEffect("Hit Effect", "HITEFFECT_ON", 46, 48); + GenericEffect("Negative", "NEGATIVE_ON", 49, 49); + GenericEffect("Pixelate", "PIXELATE_ON", 50, 50, true, "Looks bad with distorition effects"); + GreyScale("GreyScale", "GREYSCALE_ON"); + Posterize("Posterize", "POSTERIZE_ON"); + Blur("Blur", "BLUR_ON"); + GenericEffect("Motion Blur", "MOTIONBLUR_ON", 62, 63); + GenericEffect("Ghost", "GHOST_ON", 64, 65, true, "This effect will not affect the outline", new int[] { 157 }); + GenericEffect("Hologram", "HOLOGRAM_ON", 73, 77, true, null, new int[] { 140, 158 }); + GenericEffect("Chromatic Aberration", "CHROMABERR_ON", 78, 79); + if(!isShaderSRP) GenericEffect("Glitch", "GLITCH_ON", 80, 80, true, null, new int[] { 139, 172 }); + else GenericEffect("Glitch", "GLITCH_ON", 80, 80, true, null, new int[] { 139, 179 }); + GenericEffect("Flicker", "FLICKER_ON", 81, 83); + GenericEffect("Shadow", "SHADOW_ON", 84, 87); + GenericEffect("Shine", "SHINE_ON", 133, 138); + GenericEffect("Contrast & Brightness", "CONTRAST_ON", 152, 153); + Overlay("Overlay Texture", "OVERLAY_ON", isShaderSRP); + GenericEffect("Alpha Cutoff", "ALPHACUTOFF_ON", 70, 70); + GenericEffect("Alpha Round", "ALPHAROUND_ON", 144, 144); + } + + DrawLine(Color.grey, 1, 3); + GUILayout.Label("UV Effects", bigLabelStyle); + + currEnabledDrawers[uvFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[uvFxShapeDrawer], new GUIContent("Show UV Effects"), toggleButtonStyle); + if(currEnabledDrawers[uvFxShapeDrawer]) + { + GenericEffect("Hand Drawn", "DOODLE_ON", 88, 89); + Grass("Grass Movement / Wind", "WIND_ON"); + GenericEffect("Wave", "WAVEUV_ON", 94, 98); + GenericEffect("Round Wave", "ROUNDWAVEUV_ON", 127, 128); + GenericEffect("Rect Size (Enable wireframe to see result)", "RECTSIZE_ON", 99, 99, true, "Only on single sprites spritesheets NOT supported"); + GenericEffect("Offset", "OFFSETUV_ON", 100, 101); + GenericEffect("Clipping / Fill Amount", "CLIPPING_ON", 102, 105); + GenericEffect("Radial Clipping / Radial Fill", "RADIALCLIPPING_ON", 164, 166); + GenericEffect("Texture Scroll", "TEXTURESCROLL_ON", 106, 107, true, "Set Texture Wrap Mode to Repeat"); + GenericEffect("Zoom", "ZOOMUV_ON", 108, 108); + if (isShaderSRP) + { + GenericEffect("Distortion", "DISTORT_ON", 109, 112, true, null, new int[] { 177 }); + } + else + { + GenericEffect("Distortion", "DISTORT_ON", 109, 112); + } + + GenericEffect("Warp Distortion", "WARP_ON", 167, 169); + GenericEffect("Twist", "TWISTUV_ON", 113, 116); + GenericEffect("Rotate", "ROTATEUV_ON", 117, 117, true, "_Tip_ Use Clipping effect to avoid possible undesired parts"); + GenericEffect("Polar Coordinates (Tile texture for good results)", "POLARUV_ON", -1, -1); + GenericEffect("Fish Eye", "FISHEYE_ON", 118, 118); + GenericEffect("Pinch", "PINCH_ON", 119, 119); + GenericEffect("Shake", "SHAKEUV_ON", 120, 122); + } + + SetAndSaveEnabledDrawers(iniDrawers); + } + + private void SetAndSaveEnabledDrawers(uint iniDrawers) + { + uint currDrawers = 0; + for(int i = 0; i < currEnabledDrawers.Length; i++) + { + if(currEnabledDrawers[i]) currDrawers |= materialDrawers[i]; + } + + if(iniDrawers != currDrawers) ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue = currDrawers; + } + + private void Blending() + { + MaterialProperty srcM = ShaderGUI.FindProperty("_MySrcMode", matProperties); + MaterialProperty dstM = ShaderGUI.FindProperty("_MyDstMode", matProperties); + if(srcM.floatValue == 0 && dstM.floatValue == 0) + { + srcM.floatValue = 5; + dstM.floatValue = 10; + } + + GUILayout.Label("Look for 'ShaderLab: Blending' if you don't know what this is", smallLabelStyle); + if(GUILayout.Button("Back To Default Blending")) + { + srcM.floatValue = 5; + dstM.floatValue = 10; + targetMat.DisableKeyword("PREMULTIPLYALPHA_ON"); + } + + srcMode = (BlendMode)srcM.floatValue; + dstMode = (BlendMode)dstM.floatValue; + srcMode = (BlendMode)EditorGUILayout.EnumPopup("SrcMode", srcMode); + dstMode = (BlendMode)EditorGUILayout.EnumPopup("DstMode", dstMode); + srcM.floatValue = (float)(srcMode); + dstM.floatValue = (float)(dstMode); + + bool ini = oldKeyWords.Contains("PREMULTIPLYALPHA_ON"); + bool toggle = EditorGUILayout.Toggle("Premultiply Alpha?", ini); + if(ini != toggle) Save(); + if(toggle) targetMat.EnableKeyword("PREMULTIPLYALPHA_ON"); + else targetMat.DisableKeyword("PREMULTIPLYALPHA_ON"); + } + + private void Billboard(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = inspector; + toggle = GUILayout.Toggle(toggle, effectNameLabel); + + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + GUILayout.Label("Don't use this feature on UI elements!", smallLabelStyle); + DrawProperty(129, true); + MaterialProperty billboardY = matProperties[129]; + if(billboardY.floatValue == 1) targetMat.EnableKeyword("BILBOARDY_ON"); + else targetMat.DisableKeyword("BILBOARDY_ON"); + } + else targetMat.DisableKeyword(keyword); + } + + private void ZWrite() + { + MaterialProperty zWrite = ShaderGUI.FindProperty("_ZWrite", matProperties); + bool toggle = zWrite.floatValue > 0.9f ? true : false; + EditorGUILayout.BeginHorizontal(); + { + float tempValue = zWrite.floatValue; + toggle = GUILayout.Toggle(toggle, new GUIContent("Enable Z Write")); + if(toggle) zWrite.floatValue = 1.0f; + else zWrite.floatValue = 0.0f; + if(tempValue != zWrite.floatValue && !Application.isPlaying) Save(); + } + EditorGUILayout.EndHorizontal(); + } + + private void ZTest() + { + MaterialProperty zTestM = ShaderGUI.FindProperty("_ZTestMode", matProperties); + float tempValue = zTestM.floatValue; + zTestMode = (UnityEngine.Rendering.CompareFunction)zTestM.floatValue; + zTestMode = (UnityEngine.Rendering.CompareFunction)EditorGUILayout.EnumPopup("Z TestMode", zTestMode); + zTestM.floatValue = (float)(zTestMode); + if(tempValue != zTestM.floatValue && !Application.isPlaying) Save(); + } + + private void Culling() + { + MaterialProperty cullO = ShaderGUI.FindProperty("_CullingOption", matProperties);; + float tempValue = cullO.floatValue; + cullMode = (UnityEngine.Rendering.CullMode)cullO.floatValue; + cullMode = (UnityEngine.Rendering.CullMode)EditorGUILayout.EnumPopup("Culling Mode", cullMode); + cullO.floatValue = (float)(cullMode); + if(tempValue != cullO.floatValue && !Application.isPlaying) Save(); + } + + private void SpriteAtlas(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + toggle = GUILayout.Toggle(toggle, inspector); + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + EditorGUILayout.BeginVertical(propertiesStyle); + { + GUILayout.Label("Make sure SpriteAtlasUV component is added \n " + + "*Check documentation if unsure what this does or how it works", smallLabelStyle); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + } + + private void Outline(string inspector, string keyword, bool isSRPShader) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + ".Outline"; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("OUTBASE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(14); + DrawProperty(15); + DrawProperty(16); + DrawEffectSubKeywordToggle("Outline High Resolution?", "OUTBASE8DIR_ON"); + + DrawLine(Color.grey, 1, 3); + bool outlinePixelPerf = DrawEffectSubKeywordToggle("Outline is Pixel Perfect?", "OUTBASEPIXELPERF_ON"); + if(outlinePixelPerf) DrawProperty(18); + else DrawProperty(17); + + DrawLine(Color.grey, 1, 3); + bool outlineTexture = DrawEffectSubKeywordToggle("Outline uses texture?", "OUTTEX_ON"); + if(outlineTexture) + { + DrawProperty(19); + DrawProperty(20); + DrawProperty(21); + + if (isSRPShader) + { + DrawProperty(175); + } + } + + DrawLine(Color.grey, 1, 3); + bool outlineDistort = DrawEffectSubKeywordToggle("Outline uses distortion?", "OUTDIST_ON"); + if(outlineDistort) + { + DrawProperty(22); + DrawProperty(23); + DrawProperty(24); + DrawProperty(25); + + if (isSRPShader) + { + DrawProperty(176); + } + } + + DrawLine(Color.grey, 1, 3); + DrawEffectSubKeywordToggle("Only render outline?", "ONLYOUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("OUTBASE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void GenericEffect(string inspector, string keyword, int first, int last, bool effectCounter = true, string preMessage = null, int[] extraProperties = null, bool boldToggleLetters = true) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + if(effectCounter) + { + effectNameLabel.text = effectCount + "." + inspector; + effectCount++; + } + else effectNameLabel.text = inspector; + if(boldToggleLetters) toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + else toggle = GUILayout.Toggle(toggle, effectNameLabel); + + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + if(first > 0) + { + EditorGUILayout.BeginVertical(propertiesStyle); + { + if(preMessage != null) GUILayout.Label(preMessage, smallLabelStyle); + for(int i = first; i <= last; i++) DrawProperty(i); + if(extraProperties != null) + foreach(int i in extraProperties) + DrawProperty(i); + } + EditorGUILayout.EndVertical(); + } + } + else targetMat.DisableKeyword(keyword); + + if(boldToggleLetters) EditorGUILayout.EndToggleGroup(); + } + + private void Glow(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("GLOW_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool useGlowTex = DrawEffectSubKeywordToggle("Use Glow Texture?", "GLOWTEX_ON"); + if(useGlowTex) DrawProperty(6); + + DrawProperty(3); + DrawProperty(4); + DrawProperty(5, true); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("GLOW_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void ColorRamp(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("COLORRAMP_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool useEditableGradient = false; + if(AssetDatabase.Contains(targetMat)) + { + useEditableGradient = oldKeyWords.Contains("GRADIENTCOLORRAMP_ON"); + bool gradientTex = useEditableGradient; + gradientTex = GUILayout.Toggle(gradientTex, new GUIContent("Use Editable Gradient?")); + if(useEditableGradient != gradientTex) + { + Save(); + if(gradientTex) + { + useEditableGradient = true; + targetMat.EnableKeyword("GRADIENTCOLORRAMP_ON"); + } + else targetMat.DisableKeyword("GRADIENTCOLORRAMP_ON"); + } + + if(useEditableGradient) matEditor.ShaderProperty(matProperties[159], matProperties[159].displayName); + } + else GUILayout.Label("*Save to folder to allow for dynamic Gradient property", smallLabelStyle); + + if(!useEditableGradient) DrawProperty(51); + + DrawProperty(52); + DrawProperty(53, true); + MaterialProperty colorRampOut = matProperties[53]; + if(colorRampOut.floatValue == 1) targetMat.EnableKeyword("COLORRAMPOUTLINE_ON"); + else targetMat.DisableKeyword("COLORRAMPOUTLINE_ON"); + DrawProperty(155); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("COLORRAMP_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void ColorChange(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("CHANGECOLOR_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + for(int i = 123; i < 127; i++) DrawProperty(i); + + DrawLine(Color.grey, 1, 3); + ini = oldKeyWords.Contains("CHANGECOLOR2_ON"); + bool toggle2 = ini; + toggle2 = EditorGUILayout.Toggle("Use Color 2", ini); + if(ini != toggle2) Save(); + if(toggle2) + { + targetMat.EnableKeyword("CHANGECOLOR2_ON"); + for(int i = 146; i < 149; i++) DrawProperty(i); + } + else targetMat.DisableKeyword("CHANGECOLOR2_ON"); + + DrawLine(Color.grey, 1, 3); + ini = oldKeyWords.Contains("CHANGECOLOR3_ON"); + toggle2 = ini; + toggle2 = EditorGUILayout.Toggle("Use Color 3", toggle2); + if(ini != toggle2) Save(); + if(toggle2) + { + targetMat.EnableKeyword("CHANGECOLOR3_ON"); + for(int i = 149; i < 152; i++) DrawProperty(i); + } + else targetMat.DisableKeyword("CHANGECOLOR3_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("CHANGECOLOR_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void GreyScale(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("GREYSCALE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(54); + DrawProperty(56); + DrawProperty(55, true); + MaterialProperty greyScaleOut = matProperties[55]; + if(greyScaleOut.floatValue == 1) targetMat.EnableKeyword("GREYSCALEOUTLINE_ON"); + else targetMat.DisableKeyword("GREYSCALEOUTLINE_ON"); + DrawProperty(156); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("GREYSCALE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Posterize(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("POSTERIZE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(57); + DrawProperty(58); + DrawProperty(59, true); + MaterialProperty posterizeOut = matProperties[59]; + if(posterizeOut.floatValue == 1) targetMat.EnableKeyword("POSTERIZEOUTLINE_ON"); + else targetMat.DisableKeyword("POSTERIZEOUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("POSTERIZE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Blur(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("BLUR_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + GUILayout.Label("This effect will not affect the outline", smallLabelStyle); + DrawProperty(60); + DrawProperty(61, true); + MaterialProperty blurIsHd = matProperties[61]; + if(blurIsHd.floatValue == 1) targetMat.EnableKeyword("BLURISHD_ON"); + else targetMat.DisableKeyword("BLURISHD_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("BLUR_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Grass(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("WIND_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(90); + DrawProperty(91); + DrawProperty(145); + DrawProperty(92); + DrawProperty(93, true); + MaterialProperty grassManual = matProperties[92]; + if(grassManual.floatValue == 1) targetMat.EnableKeyword("MANUALWIND_ON"); + else targetMat.DisableKeyword("MANUALWIND_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("WIND_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void InnerOutline(string inspector, string keyword, int first, int last) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + if(first > 0) + { + EditorGUILayout.BeginVertical(propertiesStyle); + { + for(int i = first; i <= last; i++) DrawProperty(i); + + EditorGUILayout.Separator(); + DrawProperty(72, true); + MaterialProperty onlyInOutline = matProperties[72]; + if(onlyInOutline.floatValue == 1) targetMat.EnableKeyword("ONLYINNEROUTLINE_ON"); + else targetMat.DisableKeyword("ONLYINNEROUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void Gradient(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(143, true); + MaterialProperty gradIsRadial = matProperties[143]; + if(gradIsRadial.floatValue == 1) + { + targetMat.EnableKeyword("RADIALGRADIENT_ON"); + DrawProperty(31); + DrawProperty(32); + DrawProperty(34); + DrawProperty(141); + } + else + { + targetMat.DisableKeyword("RADIALGRADIENT_ON"); + bool simpleGradient = oldKeyWords.Contains("GRADIENT2COL_ON"); + bool simpleGradToggle = EditorGUILayout.Toggle("2 Color Gradient?", simpleGradient); + if(simpleGradient && !simpleGradToggle) targetMat.DisableKeyword("GRADIENT2COL_ON"); + else if(!simpleGradient && simpleGradToggle) targetMat.EnableKeyword("GRADIENT2COL_ON"); + DrawProperty(31); + DrawProperty(32); + if(!simpleGradToggle) DrawProperty(33); + DrawProperty(34); + if(!simpleGradToggle) DrawProperty(35); + if(!simpleGradToggle) DrawProperty(141); + DrawProperty(142); + } + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void Overlay(string inspector, string keyword, bool isShaderSRP) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool multModeOn = oldKeyWords.Contains("OVERLAYMULT_ON"); + bool isMultMode = multModeOn; + isMultMode = GUILayout.Toggle(isMultMode, new GUIContent("Is overlay multiplicative?")); + if(multModeOn != isMultMode) + { + Save(); + if(isMultMode) + { + multModeOn = true; + targetMat.EnableKeyword("OVERLAYMULT_ON"); + } + else targetMat.DisableKeyword("OVERLAYMULT_ON"); + } + + if(multModeOn) GUILayout.Label("Overlay is set to multiplicative mode", smallLabelStyle); + else GUILayout.Label("Overlay is set to additive mode", smallLabelStyle); + + for(int i = 160; i <= 163; i++) DrawProperty(i); + for(int i = 170; i <= 171; i++) DrawProperty(i); + + if (isShaderSRP) + { + DrawProperty(178); + } + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void DrawProperty(int index, bool noReset = false) + { + MaterialProperty targetProperty = matProperties[index]; + + EditorGUILayout.BeginHorizontal(); + { + GUIContent propertyLabel = new GUIContent(); + propertyLabel.text = targetProperty.displayName; + propertyLabel.tooltip = targetProperty.name + " (C#)"; + + matEditor.ShaderProperty(targetProperty, propertyLabel); + + if(!noReset) + { + GUIContent resetButtonLabel = new GUIContent(); + resetButtonLabel.text = "R"; + resetButtonLabel.tooltip = "Resets to default value"; + if(GUILayout.Button(resetButtonLabel, GUILayout.Width(20))) ResetProperty(targetProperty); + } + } + EditorGUILayout.EndHorizontal(); + } + + private void ResetProperty(MaterialProperty targetProperty) + { + AllIn1ShaderPropertyType shaderProperty = EditorUtils.GetShaderTypeByMaterialProperty(targetProperty); + + if(originalMaterialCopy == null) originalMaterialCopy = new Material(targetMat.shader); + if(shaderProperty == AllIn1ShaderPropertyType.Float || shaderProperty == AllIn1ShaderPropertyType.Range) + { + targetProperty.floatValue = originalMaterialCopy.GetFloat(targetProperty.name); + } + else if(shaderProperty == AllIn1ShaderPropertyType.Vector) + { + targetProperty.vectorValue = originalMaterialCopy.GetVector(targetProperty.name); + } + else if(shaderProperty == AllIn1ShaderPropertyType.Color) + { + targetProperty.colorValue = originalMaterialCopy.GetColor(targetProperty.name); + } + else if(shaderProperty == AllIn1ShaderPropertyType.Texture) + { + targetProperty.textureValue = originalMaterialCopy.GetTexture(targetProperty.name); + } + } + + private bool DrawEffectSubKeywordToggle(string inspector, string keyword, bool setCustomConfigAfter = false) + { + GUIContent propertyLabel = new GUIContent(); + propertyLabel.text = inspector; + propertyLabel.tooltip = keyword + " (C#)"; + + bool ini = oldKeyWords.Contains(keyword); + bool toggle = ini; + toggle = GUILayout.Toggle(toggle, propertyLabel); + if(ini != toggle) + { + if(toggle) targetMat.EnableKeyword(keyword); + else targetMat.DisableKeyword(keyword); + } + + return toggle; + } + + private void Save() + { + if(!Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + EditorUtility.SetDirty(targetMat); + } + + private void DrawLine(Color color, int thickness = 2, int padding = 10) + { + Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness)); + r.height = thickness; + r.y += (padding / 2); + r.x -= 2; + r.width += 6; + EditorGUI.DrawRect(r, color); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderMaterialInspector.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderMaterialInspector.cs.meta new file mode 100644 index 0000000..8254a0a --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderMaterialInspector.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: f42211545c188ae41b1e35cc1ce38187 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderMaterialInspector.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderUiMaskMaterialInspector.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderUiMaskMaterialInspector.cs new file mode 100644 index 0000000..60c642b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderUiMaskMaterialInspector.cs @@ -0,0 +1,764 @@ +#if UNITY_EDITOR +using System.Linq; +using AllIn1SpriteShader; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; +using UnityEngine.Rendering; + +namespace AllIn1SpriteShader +{ + [CanEditMultipleObjects] + public class AllIn1SpriteShaderUiMaskMaterialInspector : ShaderGUI + { + private Material targetMat; + private BlendMode srcMode, dstMode; + + private GUIStyle propertiesStyle, bigLabelStyle, smallLabelStyle, toggleButtonStyle; + private const int bigFontSize = 16, smallFontSize = 11; + private string[] oldKeyWords; + private int effectCount = 1; + private Material originalMaterialCopy; + private MaterialEditor matEditor; + private MaterialProperty[] matProperties; + private uint[] materialDrawers = new uint[] { 1, 2, 4 }; + bool[] currEnabledDrawers; + private const uint advancedConfigDrawer = 0; + private const uint colorFxShapeDrawer = 1; + private const uint uvFxShapeDrawer = 2; + + public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) + { + matEditor = materialEditor; + matProperties = properties; + targetMat = materialEditor.target as Material; + effectCount = 1; + oldKeyWords = targetMat.shaderKeywords; + propertiesStyle = new GUIStyle(EditorStyles.helpBox); + propertiesStyle.margin = new RectOffset(0, 0, 0, 0); + bigLabelStyle = new GUIStyle(EditorStyles.boldLabel); + bigLabelStyle.fontSize = bigFontSize; + smallLabelStyle = new GUIStyle(EditorStyles.boldLabel); + smallLabelStyle.fontSize = smallFontSize; + toggleButtonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleCenter, richText = true }; + currEnabledDrawers = new bool[materialDrawers.Length]; + uint iniDrawers = (uint)ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue; + for(int i = 0; i < materialDrawers.Length; i++) currEnabledDrawers[i] = (materialDrawers[i] & iniDrawers) > 0; + + GUILayout.Label("General Properties", bigLabelStyle); + DrawProperty(0); + DrawProperty(1); + DrawProperty(2); + + + currEnabledDrawers[advancedConfigDrawer] = GUILayout.Toggle(currEnabledDrawers[advancedConfigDrawer], new GUIContent("Show Advanced Configuration"), toggleButtonStyle); + if(currEnabledDrawers[advancedConfigDrawer]) + { + + EditorGUILayout.BeginVertical(propertiesStyle); + Blending(); + DrawLine(Color.grey, 1, 3); + SpriteAtlas("Sprite inside an atlas?", "ATLAS_ON"); + DrawLine(Color.grey, 1, 3); + materialEditor.EnableInstancingField(); + DrawLine(Color.grey, 1, 3); + materialEditor.RenderQueueField(); + EditorGUILayout.EndVertical(); + } + + EditorGUILayout.Separator(); + DrawLine(Color.grey, 1, 3); + GUILayout.Label("Color Effects", bigLabelStyle); + + currEnabledDrawers[colorFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[colorFxShapeDrawer], new GUIContent("Show Color Effects"), toggleButtonStyle); + if(currEnabledDrawers[colorFxShapeDrawer]) + { + Glow("Glow", "GLOW_ON"); + GenericEffect("Fade", "FADE_ON", 7, 13); + Outline("Outline", "OUTBASE_ON"); + GenericEffect("Alpha Outline", "ALPHAOUTLINE_ON", 26, 30, true, "A more performant but less flexible outline"); + InnerOutline("Inner Outline", "INNEROUTLINE_ON", 66, 69); + Gradient("Gradient & Radial Gradient", "GRADIENT_ON"); + GenericEffect("Color Swap", "COLORSWAP_ON", 36, 42, true, "You will need a mask texture (see Documentation)", new int[] { 154 }); + GenericEffect("Hue Shift", "HSV_ON", 43, 45); + ColorChange("Change 1 Color", "CHANGECOLOR_ON"); + ColorRamp("Color Ramp", "COLORRAMP_ON"); + GenericEffect("Hit Effect", "HITEFFECT_ON", 46, 48); + GenericEffect("Negative", "NEGATIVE_ON", 49, 49); + GenericEffect("Pixelate", "PIXELATE_ON", 50, 50, true, "Looks bad with distorition effects"); + GreyScale("GreyScale", "GREYSCALE_ON"); + Posterize("Posterize", "POSTERIZE_ON"); + Blur("Blur", "BLUR_ON"); + GenericEffect("Motion Blur", "MOTIONBLUR_ON", 62, 63); + GenericEffect("Ghost", "GHOST_ON", 64, 65, true, "This effect will not affect the outline", new int[] { 157 }); + GenericEffect("Hologram", "HOLOGRAM_ON", 73, 77, true, null, new int[] { 140, 158 }); + GenericEffect("Chromatic Aberration", "CHROMABERR_ON", 78, 79); + GenericEffect("Glitch", "GLITCH_ON", 80, 80, true, null, new int[] { 139, 172 }); + GenericEffect("Flicker", "FLICKER_ON", 81, 83); + GenericEffect("Shadow", "SHADOW_ON", 84, 87); + GenericEffect("Shine", "SHINE_ON", 133, 138); + GenericEffect("Contrast & Brightness", "CONTRAST_ON", 152, 153); + Overlay("Overlay Texture", "OVERLAY_ON"); + GenericEffect("Alpha Cutoff", "ALPHACUTOFF_ON", 70, 70); + GenericEffect("Alpha Round", "ALPHAROUND_ON", 144, 144); + } + + DrawLine(Color.grey, 1, 3); + GUILayout.Label("UV Effects", bigLabelStyle); + + currEnabledDrawers[uvFxShapeDrawer] = GUILayout.Toggle(currEnabledDrawers[uvFxShapeDrawer], new GUIContent("Show Alpha Effects"), toggleButtonStyle); + if(currEnabledDrawers[uvFxShapeDrawer]) + { + GenericEffect("Hand Drawn", "DOODLE_ON", 88, 89); + Grass("Grass Movement / Wind", "WIND_ON"); + GenericEffect("Wave", "WAVEUV_ON", 94, 98); + GenericEffect("Round Wave", "ROUNDWAVEUV_ON", 127, 128); + GenericEffect("Rect Size (Enable wireframe to see result)", "RECTSIZE_ON", 99, 99, true, "Only on single sprites spritesheets NOT supported"); + GenericEffect("Offset", "OFFSETUV_ON", 100, 101); + GenericEffect("Clipping / Fill Amount", "CLIPPING_ON", 102, 105); + GenericEffect("Radial Clipping / Radial Fill", "RADIALCLIPPING_ON", 164, 166); + GenericEffect("Texture Scroll", "TEXTURESCROLL_ON", 106, 107, true, "Set Texture Wrap Mode to Repeat"); + GenericEffect("Zoom", "ZOOMUV_ON", 108, 108); + GenericEffect("Distortion", "DISTORT_ON", 109, 112); + GenericEffect("Warp Distortion", "WARP_ON", 167, 169); + GenericEffect("Twist", "TWISTUV_ON", 113, 116); + GenericEffect("Rotate", "ROTATEUV_ON", 117, 117, true, "_Tip_ Use Clipping effect to avoid possible undesired parts"); + GenericEffect("Polar Coordinates (Tile texture for good results)", "POLARUV_ON", -1, -1); + GenericEffect("Fish Eye", "FISHEYE_ON", 118, 118); + GenericEffect("Pinch", "PINCH_ON", 119, 119); + GenericEffect("Shake", "SHAKEUV_ON", 120, 122); + } + + SetAndSaveEnabledDrawers(iniDrawers); + } + + private void SetAndSaveEnabledDrawers(uint iniDrawers) + { + uint currDrawers = 0; + for(int i = 0; i < currEnabledDrawers.Length; i++) + { + if(currEnabledDrawers[i]) currDrawers |= materialDrawers[i]; + } + + if(iniDrawers != currDrawers) ShaderGUI.FindProperty("_EditorDrawers", matProperties).floatValue = currDrawers; + } + + private void Blending() + { + MaterialProperty srcM = ShaderGUI.FindProperty("_MySrcMode", matProperties); + MaterialProperty dstM = ShaderGUI.FindProperty("_MyDstMode", matProperties); + if(srcM.floatValue == 0 && dstM.floatValue == 0) + { + srcM.floatValue = 5; + dstM.floatValue = 10; + } + + GUILayout.Label("Look for 'ShaderLab: Blending' if you don't know what this is", smallLabelStyle); + if(GUILayout.Button("Back To Default Blending")) + { + srcM.floatValue = 5; + dstM.floatValue = 10; + targetMat.DisableKeyword("PREMULTIPLYALPHA_ON"); + } + + srcMode = (BlendMode)srcM.floatValue; + dstMode = (BlendMode)dstM.floatValue; + srcMode = (BlendMode)EditorGUILayout.EnumPopup("SrcMode", srcMode); + dstMode = (BlendMode)EditorGUILayout.EnumPopup("DstMode", dstMode); + srcM.floatValue = (float)(srcMode); + dstM.floatValue = (float)(dstMode); + + bool ini = oldKeyWords.Contains("PREMULTIPLYALPHA_ON"); + bool toggle = EditorGUILayout.Toggle("Premultiply Alpha?", ini); + if(ini != toggle) Save(); + if(toggle) targetMat.EnableKeyword("PREMULTIPLYALPHA_ON"); + else targetMat.DisableKeyword("PREMULTIPLYALPHA_ON"); + } + + private void SpriteAtlas(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + toggle = GUILayout.Toggle(toggle, inspector); + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + EditorGUILayout.BeginVertical(propertiesStyle); + { + GUILayout.Label("Make sure SpriteAtlasUV component is added \n " + + "*Check documentation if unsure what this does or how it works", smallLabelStyle); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + } + + private void Outline(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + ".Outline"; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("OUTBASE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(14); + DrawProperty(15); + DrawProperty(16); + DrawEffectSubKeywordToggle("Outline High Resolution?", "OUTBASE8DIR_ON"); + + DrawLine(Color.grey, 1, 3); + bool outlinePixelPerf = DrawEffectSubKeywordToggle("Outline is Pixel Perfect?", "OUTBASEPIXELPERF_ON"); + if(outlinePixelPerf) DrawProperty(18); + else DrawProperty(17); + + DrawLine(Color.grey, 1, 3); + bool outlineTexture = DrawEffectSubKeywordToggle("Outline uses texture?", "OUTTEX_ON"); + if(outlineTexture) + { + DrawProperty(19); + DrawProperty(20); + DrawProperty(21); + } + + DrawLine(Color.grey, 1, 3); + bool outlineDistort = DrawEffectSubKeywordToggle("Outline uses distortion?", "OUTDIST_ON"); + if(outlineDistort) + { + DrawProperty(22); + DrawProperty(23); + DrawProperty(24); + DrawProperty(25); + } + + DrawLine(Color.grey, 1, 3); + DrawEffectSubKeywordToggle("Only render outline?", "ONLYOUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("OUTBASE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void GenericEffect(string inspector, string keyword, int first, int last, bool effectCounter = true, string preMessage = null, int[] extraProperties = null, bool boldToggleLetters = true) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + if(effectCounter) + { + effectNameLabel.text = effectCount + "." + inspector; + effectCount++; + } + else effectNameLabel.text = inspector; + if(boldToggleLetters) toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + else toggle = GUILayout.Toggle(toggle, effectNameLabel); + + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + if(first > 0) + { + EditorGUILayout.BeginVertical(propertiesStyle); + { + if(preMessage != null) GUILayout.Label(preMessage, smallLabelStyle); + for(int i = first; i <= last; i++) DrawProperty(i); + if(extraProperties != null) + foreach(int i in extraProperties) + DrawProperty(i); + } + EditorGUILayout.EndVertical(); + } + } + else targetMat.DisableKeyword(keyword); + + if(boldToggleLetters) EditorGUILayout.EndToggleGroup(); + } + + private void Glow(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("GLOW_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool useGlowTex = DrawEffectSubKeywordToggle("Use Glow Texture?", "GLOWTEX_ON"); + if(useGlowTex) DrawProperty(6); + + DrawProperty(3); + DrawProperty(4); + DrawProperty(5, true); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("GLOW_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void ColorRamp(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("COLORRAMP_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool useEditableGradient = false; + if(AssetDatabase.Contains(targetMat)) + { + useEditableGradient = oldKeyWords.Contains("GRADIENTCOLORRAMP_ON"); + bool gradientTex = useEditableGradient; + gradientTex = GUILayout.Toggle(gradientTex, new GUIContent("Use Editable Gradient?")); + if(useEditableGradient != gradientTex) + { + Save(); + if(gradientTex) + { + useEditableGradient = true; + targetMat.EnableKeyword("GRADIENTCOLORRAMP_ON"); + } + else targetMat.DisableKeyword("GRADIENTCOLORRAMP_ON"); + } + + if(useEditableGradient) matEditor.ShaderProperty(matProperties[159], matProperties[159].displayName); + } + else GUILayout.Label("*Save to folder to allow for dynamic Gradient property", smallLabelStyle); + + if(!useEditableGradient) DrawProperty(51); + + DrawProperty(52); + DrawProperty(53, true); + MaterialProperty colorRampOut = matProperties[53]; + if(colorRampOut.floatValue == 1) targetMat.EnableKeyword("COLORRAMPOUTLINE_ON"); + else targetMat.DisableKeyword("COLORRAMPOUTLINE_ON"); + DrawProperty(155); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("COLORRAMP_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void ColorChange(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("CHANGECOLOR_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + for(int i = 123; i < 127; i++) DrawProperty(i); + + DrawLine(Color.grey, 1, 3); + ini = oldKeyWords.Contains("CHANGECOLOR2_ON"); + bool toggle2 = ini; + toggle2 = EditorGUILayout.Toggle("Use Color 2", ini); + if(ini != toggle2) Save(); + if(toggle2) + { + targetMat.EnableKeyword("CHANGECOLOR2_ON"); + for(int i = 146; i < 149; i++) DrawProperty(i); + } + else targetMat.DisableKeyword("CHANGECOLOR2_ON"); + + DrawLine(Color.grey, 1, 3); + ini = oldKeyWords.Contains("CHANGECOLOR3_ON"); + toggle2 = ini; + toggle2 = EditorGUILayout.Toggle("Use Color 3", toggle2); + if(ini != toggle2) Save(); + if(toggle2) + { + targetMat.EnableKeyword("CHANGECOLOR3_ON"); + for(int i = 149; i < 152; i++) DrawProperty(i); + } + else targetMat.DisableKeyword("CHANGECOLOR3_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("CHANGECOLOR_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void GreyScale(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("GREYSCALE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(54); + DrawProperty(56); + DrawProperty(55, true); + MaterialProperty greyScaleOut = matProperties[55]; + if(greyScaleOut.floatValue == 1) targetMat.EnableKeyword("GREYSCALEOUTLINE_ON"); + else targetMat.DisableKeyword("GREYSCALEOUTLINE_ON"); + DrawProperty(156); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("GREYSCALE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Posterize(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("POSTERIZE_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(57); + DrawProperty(58); + DrawProperty(59, true); + MaterialProperty posterizeOut = matProperties[59]; + if(posterizeOut.floatValue == 1) targetMat.EnableKeyword("POSTERIZEOUTLINE_ON"); + else targetMat.DisableKeyword("POSTERIZEOUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("POSTERIZE_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Blur(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("BLUR_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + GUILayout.Label("This effect will not affect the outline", smallLabelStyle); + DrawProperty(60); + DrawProperty(61, true); + MaterialProperty blurIsHd = matProperties[61]; + if(blurIsHd.floatValue == 1) targetMat.EnableKeyword("BLURISHD_ON"); + else targetMat.DisableKeyword("BLURISHD_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("BLUR_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void Grass(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword("WIND_ON"); + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(90); + DrawProperty(91); + DrawProperty(145); + DrawProperty(92); + DrawProperty(93, true); + MaterialProperty grassManual = matProperties[92]; + if(grassManual.floatValue == 1) targetMat.EnableKeyword("MANUALWIND_ON"); + else targetMat.DisableKeyword("MANUALWIND_ON"); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword("WIND_ON"); + + EditorGUILayout.EndToggleGroup(); + } + + private void InnerOutline(string inspector, string keyword, int first, int last) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + if(first > 0) + { + EditorGUILayout.BeginVertical(propertiesStyle); + { + for(int i = first; i <= last; i++) DrawProperty(i); + + EditorGUILayout.Separator(); + DrawProperty(72, true); + MaterialProperty onlyInOutline = matProperties[72]; + if(onlyInOutline.floatValue == 1) targetMat.EnableKeyword("ONLYINNEROUTLINE_ON"); + else targetMat.DisableKeyword("ONLYINNEROUTLINE_ON"); + } + EditorGUILayout.EndVertical(); + } + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void Gradient(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + + EditorGUILayout.BeginVertical(propertiesStyle); + { + DrawProperty(143, true); + MaterialProperty gradIsRadial = matProperties[143]; + if(gradIsRadial.floatValue == 1) + { + targetMat.EnableKeyword("RADIALGRADIENT_ON"); + DrawProperty(31); + DrawProperty(32); + DrawProperty(34); + DrawProperty(141); + } + else + { + targetMat.DisableKeyword("RADIALGRADIENT_ON"); + bool simpleGradient = oldKeyWords.Contains("GRADIENT2COL_ON"); + bool simpleGradToggle = EditorGUILayout.Toggle("2 Color Gradient?", simpleGradient); + if(simpleGradient && !simpleGradToggle) targetMat.DisableKeyword("GRADIENT2COL_ON"); + else if(!simpleGradient && simpleGradToggle) targetMat.EnableKeyword("GRADIENT2COL_ON"); + DrawProperty(31); + DrawProperty(32); + if(!simpleGradToggle) DrawProperty(33); + DrawProperty(34); + if(!simpleGradToggle) DrawProperty(35); + if(!simpleGradToggle) DrawProperty(141); + DrawProperty(142); + } + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void Overlay(string inspector, string keyword) + { + bool toggle = oldKeyWords.Contains(keyword); + bool ini = toggle; + + GUIContent effectNameLabel = new GUIContent(); + effectNameLabel.tooltip = keyword + " (C#)"; + effectNameLabel.text = effectCount + "." + inspector; + toggle = EditorGUILayout.BeginToggleGroup(effectNameLabel, toggle); + + effectCount++; + if(ini != toggle) Save(); + if(toggle) + { + targetMat.EnableKeyword(keyword); + EditorGUILayout.BeginVertical(propertiesStyle); + { + bool multModeOn = oldKeyWords.Contains("OVERLAYMULT_ON"); + bool isMultMode = multModeOn; + isMultMode = GUILayout.Toggle(isMultMode, new GUIContent("Is overlay multiplicative?")); + if(multModeOn != isMultMode) + { + Save(); + if(isMultMode) + { + multModeOn = true; + targetMat.EnableKeyword("OVERLAYMULT_ON"); + } + else targetMat.DisableKeyword("OVERLAYMULT_ON"); + } + + if(multModeOn) GUILayout.Label("Overlay is set to multiplicative mode", smallLabelStyle); + else GUILayout.Label("Overlay is set to additive mode", smallLabelStyle); + + for(int i = 160; i <= 163; i++) DrawProperty(i); + for(int i = 170; i <= 171; i++) DrawProperty(i); + } + EditorGUILayout.EndVertical(); + } + else targetMat.DisableKeyword(keyword); + + EditorGUILayout.EndToggleGroup(); + } + + private void DrawProperty(int index, bool noReset = false) + { + MaterialProperty targetProperty = matProperties[index]; + + EditorGUILayout.BeginHorizontal(); + { + GUIContent propertyLabel = new GUIContent(); + propertyLabel.text = targetProperty.displayName; + propertyLabel.tooltip = targetProperty.name + " (C#)"; + + matEditor.ShaderProperty(targetProperty, propertyLabel); + + if(!noReset) + { + GUIContent resetButtonLabel = new GUIContent(); + resetButtonLabel.text = "R"; + resetButtonLabel.tooltip = "Resets to default value"; + if(GUILayout.Button(resetButtonLabel, GUILayout.Width(20))) ResetProperty(targetProperty); + } + } + EditorGUILayout.EndHorizontal(); + } + + private void ResetProperty(MaterialProperty targetProperty) + { + AllIn1ShaderPropertyType propertyType = EditorUtils.GetShaderTypeByMaterialProperty(targetProperty); + + if(originalMaterialCopy == null) originalMaterialCopy = new Material(targetMat.shader); + if(propertyType == AllIn1ShaderPropertyType.Float || propertyType == AllIn1ShaderPropertyType.Range) + { + targetProperty.floatValue = originalMaterialCopy.GetFloat(targetProperty.name); + } + else if(propertyType == AllIn1ShaderPropertyType.Vector) + { + targetProperty.vectorValue = originalMaterialCopy.GetVector(targetProperty.name); + } + else if(propertyType == AllIn1ShaderPropertyType.Color) + { + targetProperty.colorValue = originalMaterialCopy.GetColor(targetProperty.name); + } + else if(propertyType == AllIn1ShaderPropertyType.Texture) + { + targetProperty.textureValue = originalMaterialCopy.GetTexture(targetProperty.name); + } + } + + private bool DrawEffectSubKeywordToggle(string inspector, string keyword, bool setCustomConfigAfter = false) + { + GUIContent propertyLabel = new GUIContent(); + propertyLabel.text = inspector; + propertyLabel.tooltip = keyword + " (C#)"; + + bool ini = oldKeyWords.Contains(keyword); + bool toggle = ini; + toggle = GUILayout.Toggle(toggle, propertyLabel); + if(ini != toggle) + { + if(toggle) targetMat.EnableKeyword(keyword); + else targetMat.DisableKeyword(keyword); + } + + return toggle; + } + + private void Save() + { + if(!Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + EditorUtility.SetDirty(targetMat); + } + + private void DrawLine(Color color, int thickness = 2, int padding = 10) + { + Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness)); + r.height = thickness; + r.y += (padding / 2); + r.x -= 2; + r.width += 6; + EditorGUI.DrawRect(r, color); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderUiMaskMaterialInspector.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderUiMaskMaterialInspector.cs.meta new file mode 100644 index 0000000..ca53bb2 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderUiMaskMaterialInspector.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: bcdb12210426bb34cb44a19ffb54132d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/AllIn1SpriteShaderUiMaskMaterialInspector.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/Constants.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/Constants.cs new file mode 100644 index 0000000..a711f5d --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/Constants.cs @@ -0,0 +1,7 @@ +namespace AllIn1SpriteShader +{ + public static class Constants + { + public const string MAIN_ASSEMBLY_NAME = "AllIn1SpriteShaderAssembly.asmdef"; + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/Constants.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/Constants.cs.meta new file mode 100644 index 0000000..8ce6bfb --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/Constants.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: dd7850185e6f57c4596c42efd4dccc33 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/Constants.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/EditorUtils.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/EditorUtils.cs new file mode 100644 index 0000000..e67fd8a --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/EditorUtils.cs @@ -0,0 +1,77 @@ +#if UNITY_EDITOR +using UnityEditor; + +namespace AllIn1SpriteShader +{ + public static class EditorUtils + { + public static string UnifyEOL(string text) + { + if(string.IsNullOrEmpty(text)) return text; + + text = text.Replace("\r\n", "\n"); + text = text.Replace("\r", "\n"); + return text; + } + + public static AllIn1ShaderPropertyType GetShaderTypeByMaterialProperty(MaterialProperty matProperty) + { + AllIn1ShaderPropertyType res; + +#if UNITY_6000_2_OR_NEWER + switch (matProperty.propertyType) + { + case UnityEngine.Rendering.ShaderPropertyType.Color: + res = AllIn1ShaderPropertyType.Color; + break; + case UnityEngine.Rendering.ShaderPropertyType.Float: + res = AllIn1ShaderPropertyType.Float; + break; + case UnityEngine.Rendering.ShaderPropertyType.Int: + res = AllIn1ShaderPropertyType.Int; + break; + case UnityEngine.Rendering.ShaderPropertyType.Range: + res = AllIn1ShaderPropertyType.Range; + break; + case UnityEngine.Rendering.ShaderPropertyType.Texture: + res = AllIn1ShaderPropertyType.Texture; + break; + case UnityEngine.Rendering.ShaderPropertyType.Vector: + res = AllIn1ShaderPropertyType.Vector; + break; + default: + res = AllIn1ShaderPropertyType.Vector; + break; + } +#else + switch (matProperty.type) + { + case MaterialProperty.PropType.Color: + res = AllIn1ShaderPropertyType.Color; + break; + case MaterialProperty.PropType.Float: + res = AllIn1ShaderPropertyType.Float; + break; + case MaterialProperty.PropType.Int: + res = AllIn1ShaderPropertyType.Int; + break; + case MaterialProperty.PropType.Range: + res = AllIn1ShaderPropertyType.Range; + break; + case MaterialProperty.PropType.Texture: + res = AllIn1ShaderPropertyType.Texture; + break; + case MaterialProperty.PropType.Vector: + res = AllIn1ShaderPropertyType.Vector; + break; + default: + res = AllIn1ShaderPropertyType.Vector; + break; + } +#endif + return res; + + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/EditorUtils.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/EditorUtils.cs.meta new file mode 100644 index 0000000..59f9662 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/EditorUtils.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 44cca39610f3ac740aaa53036cfef5d4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/EditorUtils.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/RenderPipelineChecker.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/RenderPipelineChecker.cs new file mode 100644 index 0000000..b5e1231 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/RenderPipelineChecker.cs @@ -0,0 +1,75 @@ +////////////////////////////////////////////////////// +// Shader Packager +// Copyright (c) Jason Booth +////////////////////////////////////////////////////// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +#if UNITY_2019_3_OR_NEWER + +// Installs custom defines for render pipelines (e.g., USING_HDRP) to enable conditional compilation +// across different pipelines. Unity doesn't provide these defines out of the box, so this helper +// simplifies cross-pipeline compatibility. + +namespace AllIn1SpriteShader +{ + public static class RenderPipelineChecker + { + private const string HDRP_PACKAGE = "HDRenderPipelineAsset"; + private const string URP_PACKAGE = "UniversalRenderPipelineAsset"; + + public static bool IsHDRP + { + get; private set; + } + public static bool IsURP + { + get; private set; + } + public static bool IsStandardRP + { + get; private set; + } + + public static void RefreshData() + { + IsHDRP = DoesTypeExist(HDRP_PACKAGE); + IsURP = DoesTypeExist(URP_PACKAGE); + + if (!(IsHDRP || IsURP)) + { + IsStandardRP = true; + } + + } + + public static bool DoesTypeExist(string className) + { + var foundType = (from assembly in AppDomain.CurrentDomain.GetAssemblies() + from type in GetTypesSafe(assembly) + where type.Name == className + select type).FirstOrDefault(); + + return foundType != null; + } + + public static IEnumerable GetTypesSafe(System.Reflection.Assembly assembly) + { + Type[] types; + + try + { + types = assembly.GetTypes(); + } + catch (ReflectionTypeLoadException e) + { + types = e.Types; + } + + return types.Where(x => x != null); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/RenderPipelineChecker.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/RenderPipelineChecker.cs.meta new file mode 100644 index 0000000..fa73fd9 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/RenderPipelineChecker.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 83ac30b66f3fe444189a98a9bb648c51 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Editor/RenderPipelineChecker.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/RandomSeed.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/RandomSeed.cs new file mode 100644 index 0000000..e933c8b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/RandomSeed.cs @@ -0,0 +1,37 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace AllIn1SpriteShader +{ + public class RandomSeed : MonoBehaviour + { + private readonly int randomSeedProperty = Shader.PropertyToID("_RandomSeed"); + private MaterialPropertyBlock propertyBlock; + + //If you want to randomize UI Images, you'll need to create different materials since materials are always shared + //This can be done at runtime with scripting or manually in the editor + private void Start() + { + Renderer renderer = GetComponent(); + if(renderer != null) + { + propertyBlock = new MaterialPropertyBlock(); + propertyBlock.SetFloat(randomSeedProperty, Random.Range(0f, 100f)); + renderer.SetPropertyBlock(propertyBlock); + } + else + { + Image image = GetComponent(); + if (image != null) + { + if (image.material != null) + { + image.material.SetFloat(randomSeedProperty, Random.Range(0, 1000f)); + } + else Debug.LogError("Missing Material on UI Image: " + gameObject.name); + } + else Debug.LogError("Missing Renderer or UI Image on: " + gameObject.name); + } + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/RandomSeed.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/RandomSeed.cs.meta new file mode 100644 index 0000000..98d325d --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/RandomSeed.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 6078fd4d3c5bd6f4087f8869458662dd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/RandomSeed.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs new file mode 100644 index 0000000..4d91e55 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs @@ -0,0 +1,179 @@ +using UnityEngine; +using UnityEngine.UI; +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace AllIn1SpriteShader +{ + [ExecuteInEditMode] + public class SetAtlasUvs : MonoBehaviour + { + [SerializeField] private bool updateEveryFrame = false; + [Tooltip("If using a Sprite Renderer it will use the material property instead of sharedMaterial"), SerializeField] private bool useMaterialInstanceIfPossible = false; + private Renderer render; + private SpriteRenderer spriteRender; + private Image uiImage; + private bool isUI = false; + private readonly int minXuv = Shader.PropertyToID("_MinXUV"); + private readonly int maxXuv = Shader.PropertyToID("_MaxXUV"); + private readonly int minYuv = Shader.PropertyToID("_MinYUV"); + private readonly int maxYuv = Shader.PropertyToID("_MaxYUV"); + + private void Start() + { + Setup(); + } + + private void Reset() + { + Setup(); + } + + private void Setup() + { + if (GetRendererReferencesIfNeeded()) GetAndSetUVs(); + if (!updateEveryFrame && Application.isPlaying && this != null) this.enabled = false; + } + + private void LateUpdate() + { + if (updateEveryFrame) + { + GetAndSetUVs(); + } + } + + public bool GetAndSetUVs() + { + if (!GetRendererReferencesIfNeeded()) return false; + + if (!isUI) + { + Sprite sprite = spriteRender.sprite; + Rect r = sprite.textureRect; + r.x /= sprite.texture.width; + r.width /= sprite.texture.width; + r.y /= sprite.texture.height; + r.height /= sprite.texture.height; + + if(useMaterialInstanceIfPossible && Application.isPlaying) + { + render.material.SetFloat(minXuv, r.xMin); + render.material.SetFloat(maxXuv, r.xMax); + render.material.SetFloat(minYuv, r.yMin); + render.material.SetFloat(maxYuv, r.yMax); + } + else + { + render.sharedMaterial.SetFloat(minXuv, r.xMin); + render.sharedMaterial.SetFloat(maxXuv, r.xMax); + render.sharedMaterial.SetFloat(minYuv, r.yMin); + render.sharedMaterial.SetFloat(maxYuv, r.yMax); + } + } + else + { + Rect r = uiImage.sprite.textureRect; + r.x /= uiImage.sprite.texture.width; + r.width /= uiImage.sprite.texture.width; + r.y /= uiImage.sprite.texture.height; + r.height /= uiImage.sprite.texture.height; + + uiImage.material.SetFloat(minXuv, r.xMin); + uiImage.material.SetFloat(maxXuv, r.xMax); + uiImage.material.SetFloat(minYuv, r.yMin); + uiImage.material.SetFloat(maxYuv, r.yMax); + } + + return true; + } + + public void ResetAtlasUvs() + { + if (!GetRendererReferencesIfNeeded()) return; + + if (!isUI) + { + if(useMaterialInstanceIfPossible && Application.isPlaying) + { + render.material.SetFloat(minXuv, 0f); + render.material.SetFloat(maxXuv, 1f); + render.material.SetFloat(minYuv, 0f); + render.material.SetFloat(maxYuv, 1f); + } + else + { + render.sharedMaterial.SetFloat(minXuv, 0f); + render.sharedMaterial.SetFloat(maxXuv, 1f); + render.sharedMaterial.SetFloat(minYuv, 0f); + render.sharedMaterial.SetFloat(maxYuv, 1f); + } + } + else + { + uiImage.material.SetFloat(minXuv, 0f); + uiImage.material.SetFloat(maxXuv, 1f); + uiImage.material.SetFloat(minYuv, 0f); + uiImage.material.SetFloat(maxYuv, 1f); + } + } + + public void UpdateEveryFrame(bool everyFrame) + { + updateEveryFrame = everyFrame; + } + + private bool GetRendererReferencesIfNeeded() + { + if (spriteRender == null) spriteRender = GetComponent(); + if (spriteRender != null) + { + if (spriteRender.sprite == null) + { + #if UNITY_EDITOR + EditorUtility.DisplayDialog("No sprite found", "The object: " + gameObject.name + ", has Sprite Renderer but no sprite", "Ok"); + #endif + DestroyImmediate(this); + return false; + } + if (render == null) render = GetComponent(); + isUI = false; + } + else + { + if (uiImage == null) + { + uiImage = GetComponent(); + if (uiImage != null) + { + #if UNITY_EDITOR + Debug.Log("You added the SetAtlasUv component to: " + gameObject.name + " that has a UI Image\n " + + "This SetAtlasUV component will only work properly on UI Images if each Image has a DIFFERENT material instance (See Documentation Sprite Atlases section for more info)"); + #endif + } + else + { + #if UNITY_EDITOR + EditorUtility.DisplayDialog("No Renderer or UI Graphic found", "This SetAtlasUV component will now get destroyed", "Ok"); + #endif + DestroyImmediate(this); + return false; + } + } + if (render == null) render = GetComponent(); + isUI = true; + } + + if (spriteRender == null && uiImage == null) + { + #if UNITY_EDITOR + EditorUtility.DisplayDialog("No Renderer or UI Graphic found", "This SetAtlasUV component will now get destroyed", "Ok"); + #endif + DestroyImmediate(this); + return false; + } + return true; + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs.meta new file mode 100644 index 0000000..8a544a1 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 1625263d85e5d554284989eb9052e863 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/SetAtlasUvs.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/SetGlobalTime.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/SetGlobalTime.cs new file mode 100644 index 0000000..ea0afbf --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/SetGlobalTime.cs @@ -0,0 +1,24 @@ +using UnityEngine; + +namespace AllIn1SpriteShader +{ + //This script is made with Unity version 2019 and onward in mind + //This script will pass in the Unscaled Time to the shader to animate the effects even when the game is paused + //Set shaders to Scaled Time variant and add this script to an active GameObject to see the results + //Video tutorial about it: https://youtu.be/7_BggIufV-w + [ExecuteInEditMode] + public class SetGlobalTime : MonoBehaviour + { + int globalTime; + + private void Start() + { + globalTime = Shader.PropertyToID("globalUnscaledTime"); + } + + private void Update() + { + Shader.SetGlobalFloat(globalTime, Time.unscaledTime / 20f); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/SetGlobalTime.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/SetGlobalTime.cs.meta new file mode 100644 index 0000000..07cc3d4 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/SetGlobalTime.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: c6c0770c7b77d3f45ab8c8d42b794c51 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/SetGlobalTime.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/SpritePropertiesSync.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/SpritePropertiesSync.cs new file mode 100644 index 0000000..58c46c7 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/SpritePropertiesSync.cs @@ -0,0 +1,92 @@ +using UnityEngine; +using UnityEngine.Rendering; + +namespace AllIn1SpriteShader +{ + [ExecuteInEditMode] + [RequireComponent(typeof(SpriteRenderer))] + public class SpritePropertiesSync : MonoBehaviour + { + public enum CastShadowMode + { + [InspectorName("Off")] OFF, + [InspectorName("One Sided")] ONE_SIDED, + [InspectorName("Two Sided")] TWO_SIDED + } + + private static int PROPID_SPRITE_FLIP = Shader.PropertyToID("_SpriteFlip"); + + public SpriteRenderer spr; + public bool isMaterialDrivenByAnimator; + + [SerializeField] private CastShadowMode shadowCastingMode = CastShadowMode.TWO_SIDED; + + private MaterialPropertyBlock matPropBlock; + + public void Start() + { + if(spr == null) spr = GetComponent(); + if(spr == null) + { + Debug.LogWarning($"Sprite Renderer is null in SpritePropertiesSync-{gameObject.name}", gameObject); + enabled = false; + return; + } + matPropBlock = new MaterialPropertyBlock(); + UpdateRendererShadowCastingMode(); + } + + private void LateUpdate() + { + if(spr == null || spr.sharedMaterial == null) + { + Debug.LogError($"Incorrect setup in SpritePropertiesSync-{gameObject.name}", gameObject); + enabled = false; + return; + } + +#if UNITY_EDITOR + if (matPropBlock == null) matPropBlock = new MaterialPropertyBlock(); + UpdateRendererShadowCastingMode(); +#endif + + UpdateMaterial(); + } + + private void UpdateRendererShadowCastingMode() + { + switch (shadowCastingMode) + { + case CastShadowMode.OFF: + spr.shadowCastingMode = ShadowCastingMode.Off; + break; + case CastShadowMode.ONE_SIDED: + spr.shadowCastingMode = ShadowCastingMode.On; + break; + case CastShadowMode.TWO_SIDED: + spr.shadowCastingMode = ShadowCastingMode.TwoSided; + break; + } + } + + private void UpdateMaterial() + { + spr.GetPropertyBlock(matPropBlock); + + float flipX = spr.flipX ? -1f : 1f; + float flipY = spr.flipY ? -1f : 1f; + Vector3 localScale = spr.transform.localScale; + float scaleSign = Mathf.Sign(localScale.x * localScale.y * localScale.z * flipX * flipY); + Vector4 vecFlip = new Vector4(flipX, flipY, flipX, flipY); + if (Application.isPlaying && isMaterialDrivenByAnimator) + { + vecFlip.x = 1.0f; + vecFlip.y = 1.0f; + } + vecFlip.z = scaleSign; + + matPropBlock.SetVector(PROPID_SPRITE_FLIP, vecFlip); + spr.SetPropertyBlock(matPropBlock); + } + } +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/SpritePropertiesSync.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/SpritePropertiesSync.cs.meta new file mode 100644 index 0000000..206ccc8 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/SpritePropertiesSync.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 38fbd5bf8eb2ab740896fa4bd7b94843 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/SpritePropertiesSync.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Texture.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Texture.meta new file mode 100644 index 0000000..e1631cb --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Texture.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 30ea7cd4d865fef46b7a1ea7e98943a1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Texture/AllIn1SpriteShaderEditorImage.png b/Assets/Plugins/AllIn1SpriteShader/Scripts/Texture/AllIn1SpriteShaderEditorImage.png new file mode 100644 index 0000000..94f5ee4 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Scripts/Texture/AllIn1SpriteShaderEditorImage.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/Texture/AllIn1SpriteShaderEditorImage.png.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/Texture/AllIn1SpriteShaderEditorImage.png.meta new file mode 100644 index 0000000..b6c1e90 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/Texture/AllIn1SpriteShaderEditorImage.png.meta @@ -0,0 +1,99 @@ +fileFormatVersion: 2 +guid: 917b41800d6604d4e99bef50da598d65 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + applyGammaDecoding: 1 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 1 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 692da10dc1b5aa741a39ec794b64c334 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/Texture/AllIn1SpriteShaderEditorImage.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/TrueShadowCompatibility.cs b/Assets/Plugins/AllIn1SpriteShader/Scripts/TrueShadowCompatibility.cs new file mode 100644 index 0000000..c4c051d --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/TrueShadowCompatibility.cs @@ -0,0 +1,39 @@ +#if LETAI_TRUESHADOW +using LeTai.TrueShadow; +using LeTai.TrueShadow.PluginInterfaces; +using UnityEngine; + +namespace AllIn1SpriteShader +{ + [ExecuteAlways] + public class TrueShadowCompatibility : MonoBehaviour, ITrueShadowCustomHashProvider + { + [Tooltip("Use with animated effects")] + public bool updateTrueShadowEveryFrame = false; + private TrueShadow shadow; + + public void UpdateTrueShadow() + { + if (!shadow) shadow = GetComponent(); + if (!shadow) return; + + UpdateTrueShadow(shadow); + } + + public static void UpdateTrueShadow(TrueShadow shadow) + { + shadow.CustomHash = Random.Range(int.MinValue, int.MaxValue); + } + + public void Update() + { + bool shouldDirty = updateTrueShadowEveryFrame; +#if UNITY_EDITOR + shouldDirty |= !Application.isPlaying; +#endif + if (shouldDirty) + UpdateTrueShadow(); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Scripts/TrueShadowCompatibility.cs.meta b/Assets/Plugins/AllIn1SpriteShader/Scripts/TrueShadowCompatibility.cs.meta new file mode 100644 index 0000000..3816f33 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Scripts/TrueShadowCompatibility.cs.meta @@ -0,0 +1,18 @@ +fileFormatVersion: 2 +guid: 279c59909b723da49b1f2cf62d25b06a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Scripts/TrueShadowCompatibility.cs + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders.meta new file mode 100644 index 0000000..5d56747 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 42ce74ee1ab07574bbe2c76ca27d7c20 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1OneShaderFunctions.cginc b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1OneShaderFunctions.cginc new file mode 100644 index 0000000..0821f15 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1OneShaderFunctions.cginc @@ -0,0 +1,71 @@ +//Prevent Unity warnings that are not relevant for this shader------------------- +#pragma warning (disable : 3571) // pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them +#pragma warning (disable : 4008) // floating point division by zero +#pragma warning (disable : 3206) // implicit truncation of vector type +//BLURS------------------------------------------------------------------------- +half4 Blur(half2 uv, sampler2D source, half Intensity) +{ + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = tex2D(source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = tex2D(source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; +} + +half BlurHD_G(half bhqp, half x) +{ + return exp(-(x * x) / (2.0 * bhqp * bhqp)); +} +half4 BlurHD(half2 uv, sampler2D source, half BlurAmount, half xScale, half yScale) +{ + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += tex2D(source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; +} +//----------------------------------------------------------------------- +half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; +} + +half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; +} + +half rand2CustomTime(half2 seed, half offset, half customTime, half speed) { + return (frac(sin(dot(seed * floor(50 + (customTime % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; +} +//----------------------------------------------------------------------- +half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1OneShaderFunctions.cginc.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1OneShaderFunctions.cginc.meta new file mode 100644 index 0000000..01f707b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1OneShaderFunctions.cginc.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: df06cdcb3555be745b54ff3003fa687e +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1OneShaderFunctions.cginc + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShader.shader b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShader.shader new file mode 100644 index 0000000..a23b342 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShader.shader @@ -0,0 +1,1234 @@ +Shader "AllIn1SpriteShader/AllIn1SpriteShader" +{ + Properties + { + _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 0.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //172 + + _ZTestMode ("Z Test Mode", Float) = 4 + _CullingOption ("Culling Option", float) = 0 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 + _EditorDrawers("Editor Drawers", Int) = 6 + } + + SubShader + { + Tags { "Queue" = "Transparent" "CanUseSpriteAtlas" = "True" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" } + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + Pass + { + CGPROGRAM + #pragma multi_compile_instancing + #pragma vertex vert + #pragma fragment frag + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local ALPHACUTOFF_ON + #pragma shader_feature_local ALPHAROUND_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature ATLAS_ON + #pragma shader_feature PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + #pragma shader_feature FOG_ON + + #include "UnityCG.cginc" + #include "AllIn1OneShaderFunctions.cginc" + + #if FOG_ON + #pragma multi_compile_fog + #endif + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half4 color : COLOR; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + half4 color : COLOR; + #if OUTTEX_ON + half2 uvOutTex : TEXCOORD1; + #endif + #if OUTDIST_ON + half2 uvOutDistTex : TEXCOORD2; + #endif + #if DISTORT_ON + half2 uvDistTex : TEXCOORD3; + #endif + #if FOG_ON + UNITY_FOG_COORDS(4) + #endif + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + sampler2D _MainTex; + half4 _MainTex_ST, _MainTex_TexelSize, _Color; + half _Alpha; + + #if ATLAS_ON + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + #endif + + #if RECTSIZE_ON + half _RectSize; + #endif + + #if OFFSETUV_ON + half _OffsetUvX, _OffsetUvY; + #endif + + #if CLIPPING_ON + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + #endif + + #if RADIALCLIPPING_ON + half _RadialStartAngle, _RadialClip, _RadialClip2; + #endif + + #if TWISTUV_ON + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + #endif + + #if ROTATEUV_ON + half _RotateUvAmount; + #endif + + #if FISHEYE_ON + half _FishEyeUvAmount; + #endif + + #if PINCH_ON + half _PinchUvAmount; + #endif + + #if DOODLE_ON + half _HandDrawnAmount, _HandDrawnSpeed; + #endif + + #if SHAKEUV_ON + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + #endif + + #if WAVEUV_ON + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + #endif + + #if ROUNDWAVEUV_ON + half _RoundWaveStrength, _RoundWaveSpeed; + #endif + + #if ZOOMUV_ON + half _ZoomUvAmount; + #endif + + #if FADE_ON + sampler2D _FadeTex, _FadeBurnTex; + half4 _FadeBurnColor, _FadeTex_ST, _FadeBurnTex_ST; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + #endif + + #if TEXTURESCROLL_ON + half _TextureScrollXSpeed, _TextureScrollYSpeed; + #endif + + #if GLOW_ON + sampler2D _GlowTex; + half4 _GlowColor; + half _Glow, _GlowGlobal; + #endif + + #if OUTBASE_ON + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + #endif + + #if OUTTEX_ON + sampler2D _OutlineTex; + half4 _OutlineTex_ST; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + #endif + + #if OUTDIST_ON + sampler2D _OutlineDistortTex; + half4 _OutlineDistortTex_ST; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + #endif + + #if DISTORT_ON + sampler2D _DistortTex; + half4 _DistortTex_ST; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + #endif + + #if WARP_ON + half _WarpStrength, _WarpSpeed, _WarpScale; + #endif + + #if WIND_ON + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + #endif + + #if GRADIENT_ON + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + #endif + + #if COLORSWAP_ON + sampler2D _ColorSwapTex; + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + #endif + + #if HSV_ON + half _HsvShift, _HsvSaturation, _HsvBright; + #endif + + #if HITEFFECT_ON + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + #endif + + #if PIXELATE_ON + half _PixelateSize; + #endif + + #if NEGATIVE_ON + half _NegativeAmount; + #endif + + #if COLORRAMP_ON + sampler2D _ColorRampTex, _ColorRampTexGradient; + half _ColorRampLuminosity, _ColorRampBlend; + #endif + + #if GREYSCALE_ON + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + #endif + + #if POSTERIZE_ON + half _PosterizeNumColors, _PosterizeGamma; + #endif + + #if BLUR_ON + half _BlurIntensity; + #endif + + #if MOTIONBLUR_ON + half _MotionBlurAngle, _MotionBlurDist; + #endif + + #if GHOST_ON + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + #endif + + #if ALPHAOUTLINE_ON + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + #endif + + #if INNEROUTLINE_ON + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + #endif + + #if HOLOGRAM_ON + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + #endif + + #if CHROMABERR_ON + half _ChromAberrAmount, _ChromAberrAlpha; + #endif + + #if GLITCH_ON + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + #endif + + #if FLICKER_ON + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + #endif + + #if SHADOW_ON + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + #endif + + #if SHINE_ON + sampler2D _ShineMask; + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + #endif + + #if ALPHACUTOFF_ON + half _AlphaCutoffValue; + #endif + + #if ALPHAROUND_ON + half _AlphaRoundThreshold; + #endif + + #if CHANGECOLOR_ON + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + #endif + #if CHANGECOLOR2_ON + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + #endif + #if CHANGECOLOR3_ON + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + #endif + + #if CONTRAST_ON + half _Contrast, _Brightness; + #endif + + #if OVERLAY_ON + sampler2D _OverlayTex; + half4 _OverlayTex_ST, _OverlayColor; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + #endif + + UNITY_INSTANCING_BUFFER_START(Props) + UNITY_DEFINE_INSTANCED_PROP(float, _RandomSeed) + UNITY_INSTANCING_BUFFER_END(Props) + + v2f vert (appdata v) + { + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + half3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + o.vertex = UnityObjectToClipPos(half4(localPos, 1)); + #else + o.vertex = UnityObjectToClipPos(v.vertex); + #endif + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.color = v.color; + + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + #if POLARUV_ON + o.uv = v.uv - center; + #endif + + #if ROTATEUV_ON + half2 uvC = v.uv; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + o.uv = mul(rot, uvC); + o.uv += center; + #endif + + #if OUTTEX_ON + o.uvOutTex = TRANSFORM_TEX(v.uv, _OutlineTex); + #endif + + #if OUTDIST_ON + o.uvOutDistTex = TRANSFORM_TEX(v.uv, _OutlineDistortTex); + #endif + + #if DISTORT_ON + o.uvDistTex = TRANSFORM_TEX(v.uv, _DistortTex); + #endif + + #if FOG_ON + UNITY_TRANSFER_FOG(o,o.vertex); + #endif + + return o; + } + + half3 GetPixel(in int offsetX, in int offsetY, half2 uv, sampler2D tex) + { + return tex2D(tex, (uv + half2(offsetX * _MainTex_TexelSize.x, offsetY * _MainTex_TexelSize.y))).rgb; + } + + half4 frag (v2f i) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + half randomSeed = UNITY_ACCESS_INSTANCED_PROP(Props, _RandomSeed); + + float2 uvRect = i.uv; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((i.uv.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ST.x, center.y * _MainTex_ST.y); + + #if CLIPPING_ON + half2 tiledUv = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + #if TEXTURESCROLL_ON && ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + + #if OFFSETUV_ON + #if ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + i.uv += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + #if POLARUV_ON + i.uv = half2(atan2(i.uv.y, i.uv.x) / (2.0f * 3.141592653589f), length(i.uv)); + i.uv *= _MainTex_ST.xy; + #endif + + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = i.uv - half2(_TwistUvPosX * _MainTex_ST.x, _TwistUvPosY * _MainTex_ST.y); + _TwistUvRadius *= (_MainTex_ST.x + _MainTex_ST.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ST.x, _TwistUvPosY * _MainTex_ST.y); + i.uv = tempUv; + #endif + + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = i.uv - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + i.uv = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + + #if PINCH_ON + half2 dP = i.uv - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + i.uv = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + #if ZOOMUV_ON + i.uv -= centerTiled; + i.uv = i.uv * _ZoomUvAmount; + i.uv += centerTiled; + #endif + + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + i.uv = lerp(i.uv, i.uv + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + i.uv += half2(xShake * 0.012, yShake * 0.01); + #endif + + #if RECTSIZE_ON + i.uv = i.uv.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + #if DISTORT_ON + #if ATLAS_ON + i.uvDistTex.x = i.uvDistTex.x * (1 / (_MaxXUV - _MinXUV)); + i.uvDistTex.y = i.uvDistTex.y * (1 / (_MaxYUV - _MinYUV)); + #endif + i.uvDistTex.x += ((_Time.x + randomSeed) * _DistortTexXSpeed) % 1; + i.uvDistTex.y += ((_Time.x + randomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (tex2D(_DistortTex, i.uvDistTex).r - 0.5) * 0.2 * _DistortAmount; + i.uv.x += distortAmnt; + i.uv.y += distortAmnt; + #endif + + #if WARP_ON + half2 warpUv = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + i.uv += warp; + #endif + + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ST.x, _WaveY * _MainTex_ST.y) - i.uv; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + i.uv = i.uv + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ST.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ST.y) - uvRect.y) * (_MainTex_TexelSize.w / _MainTex_TexelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + i.uv += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = i.uv - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + i.uv = i.uv + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + #if TEXTURESCROLL_ON && !ATLAS_ON + i.uv.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + i.uv.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + + #if PIXELATE_ON + half aspectRatio = _MainTex_TexelSize.x / _MainTex_TexelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + i.uv = floor(i.uv * pixelSize) / pixelSize; + #endif + + half4 col = tex2D(_MainTex, i.uv); + half originalAlpha = col.a; + col *= i.color; + #if PREMULTIPLYALPHA_ON + col.rgb *= col.a; + #endif + + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = tex2D(_MainTex, i.uv + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * i.color; + #endif + + #if CHROMABERR_ON + half4 r = tex2D(_MainTex, i.uv + half2(_ChromAberrAmount/10, 0)) * i.color; + half4 b = tex2D(_MainTex, i.uv + half2(-_ChromAberrAmount/10, 0)) * i.color; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * i.color; + #else + col = Blur(i.uv, _MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * i.color; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, _BlurIntensity, 1, 1) * i.color; + #else + col = Blur(i.uv, _MainTex, _BlurIntensity) * i.color; + #endif + #endif + #endif + + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + half luminance = 0; + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + + #if INNEROUTLINE_ON + half3 innerT = abs(GetPixel(0, _InnerOutlineThickness, i.uv, _MainTex) - GetPixel(0, -_InnerOutlineThickness, i.uv, _MainTex)); + innerT += abs(GetPixel(_InnerOutlineThickness, 0, i.uv, _MainTex) - GetPixel(-_InnerOutlineThickness, 0, i.uv, _MainTex)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ST.x, uvRect.y / _MainTex_ST.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (_MainTex_TexelSize.w / _MainTex_TexelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = tex2D(_ColorSwapTex, i.uv); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, tex2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, tex2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + + #if OVERLAY_ON + half2 overlayUvs = uvRect; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = tex2D(_OverlayTex, TRANSFORM_TEX(overlayUvs, _OverlayTex)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //OUTLINE------------------------------------------------------------- + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * _MainTex_TexelSize.x, _OutlinePixelWidth * _MainTex_TexelSize.y); + #else + half2 destUv = half2(_OutlineWidth * _MainTex_TexelSize.x * 200, _OutlineWidth * _MainTex_TexelSize.y * 200); + #endif + + #if OUTDIST_ON + half2 uvOutDist = uvRect; + uvOutDist.x += ((_Time.x + randomSeed) * _OutlineDistortTexXSpeed) % 1; + uvOutDist.y += ((_Time.x + randomSeed) * _OutlineDistortTexYSpeed) % 1; + half outDistortAmnt = (tex2D(_OutlineDistortTex, TRANSFORM_TEX(uvOutDist, _OutlineDistortTex)).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = tex2D(_MainTex, i.uv + half2(destUv.x, 0)).a; + half spriteRight = tex2D(_MainTex, i.uv - half2(destUv.x, 0)).a; + half spriteBottom = tex2D(_MainTex, i.uv + half2(0, destUv.y)).a; + half spriteTop = tex2D(_MainTex, i.uv - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = tex2D(_MainTex, i.uv + half2(destUv.x, destUv.y)).a; + half spriteTopRight = tex2D(_MainTex, i.uv + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = tex2D(_MainTex, i.uv + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = tex2D(_MainTex, i.uv + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + i.uvOutTex.x += ((_Time.x + randomSeed) * _OutlineTexXSpeed) % 1; + i.uvOutTex.y += ((_Time.x + randomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + i.uvOutTex = half2((i.uvOutTex.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uvOutTex.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = tex2D(_OutlineTex, i.uvOutTex); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * i.color.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //----------------------------------------------------------------------------- + + #if FADE_ON + half2 tiledUvFade1= TRANSFORM_TEX(i.uv, _FadeTex); + half2 tiledUvFade2 = TRANSFORM_TEX(i.uv, _FadeBurnTex); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = tex2D(_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * tex2D(_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + + #if SHADOW_ON + half shadowA = tex2D(_MainTex, i.uv + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * i.color.a, col.a); + #endif + + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = tex2D(_GlowTex, i.uv); + #else + emission = col; + #endif + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, tex2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, tex2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = tex2D(_ShineMask, i.uv).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + + col.a *= _Alpha; + + #if ALPHACUTOFF_ON + clip((1 - _AlphaCutoffValue) - (1 - col.a) - 0.01); + #endif + + #if ALPHAROUND_ON + col.a = step(_AlphaRoundThreshold, col.a); + #endif + + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + + col *= _Color; + + #if FOG_ON + UNITY_APPLY_FOG(i.fogCoord, col); + #endif + + return col; + } + ENDCG + } + } + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderMaterialInspector" + //Fallback "Sprites/Default" //Remove fallback so that any shader error is obvious to the user +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShader.shader.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShader.shader.meta new file mode 100644 index 0000000..f31b6e4 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShader.shader.meta @@ -0,0 +1,29 @@ +fileFormatVersion: 2 +guid: a36b7719ff0465b42ab1407d67672c5f +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _GlowTex: {instanceID: 0} + - _FadeTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + - _FadeBurnTex: {fileID: 2800000, guid: 677cca399782dea41aedc1d292ecb67d, type: 3} + - _OutlineTex: {fileID: 2800000, guid: 74087f6d03f233e4a8a142fa01f9e5cf, type: 3} + - _OutlineDistortTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, + type: 3} + - _ColorSwapTex: {instanceID: 0} + - _ColorRampTex: {fileID: 2800000, guid: 279657edc397ece4b8029c727adf6ddc, type: 3} + - _DistortTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + - _ShineMask: {instanceID: 0} + - _ColorRampTexGradient: {instanceID: 0} + - _OverlayTex: {fileID: 2800000, guid: 677cca399782dea41aedc1d292ecb67d, type: 3} + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShader.shader + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLit.shader b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLit.shader new file mode 100644 index 0000000..277b67e --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLit.shader @@ -0,0 +1,5258 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2023 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0 + [HideInInspector]_QueueControl("_QueueControl", Float) = -1 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Opaque" "UniversalMaterialType" = "Lit" "Queue" = "Geometry" } + + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Cull Back + Blend One Zero + ZTest LEqual + ZWrite On + + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + // Keywords + #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + #pragma multi_compile_fragment _ _SHADOWS_SOFT + #pragma multi_compile_fragment _ _SHADOWS_SOFT_LOW + #pragma multi_compile_fragment _ _SHADOWS_SOFT_MEDIUM + #pragma multi_compile_fragment _ _SHADOWS_SOFT_HIGH + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + //#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 + #pragma multi_compile_fragment _ _LIGHT_LAYERS + #pragma multi_compile_fragment _ DEBUG_DISPLAY + #pragma multi_compile_fragment _ _LIGHT_COOKIES + #pragma multi_compile _ _FORWARD_PLUS + #pragma multi_compile _ EVALUATE_SH_VERTEX + #pragma multi_compile _ EVALUATE_SH_MIXED + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + + // GraphKeywords: + + #define SHADER_PASS SHADERPASS_FORWARD + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define _PASSFORWARD 1 + #define _FOG_FRAGMENT 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float4 probeOcclusion : TEXCOORD8; + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float4 previousPositionCS : TEXCOORD21; // Contain previous transform position (in case of skinning for example) + float4 positionCS : TEXCOORD22; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #define GetWorldToViewMatrix() _ViewMatrix + #define UNITY_MATRIX_I_V _InvViewMatrix + #define GetViewToHClipMatrix() OptimizeProjectionMatrix(_ProjMatrix) + #define UNITY_MATRIX_I_P _InvProjMatrix + #define GetWorldToHClipMatrix() _ViewProjMatrix + #define UNITY_MATRIX_I_VP _InvViewProjMatrix + #define UNITY_MATRIX_UNJITTERED_VP _NonJitteredViewProjMatrix + #define UNITY_MATRIX_PREV_VP _PrevViewProjMatrix + #define UNITY_MATRIX_PREV_I_VP _PrevInvViewProjMatrix + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = v; + #endif + #if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); + #endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // This return the camera relative position (if enable) + float3 positionWS = TransformObjectToWorld(v.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(v.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = positionWS; + o.worldNormal = normalWS; + o.worldTangent = tangentWS; + + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + #if UNITY_VERSION < 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #if UNITY_VERSION >= 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + #elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && UNITY_VERSION >= 60000009 + OUTPUT_SH4(vertexInput.positionWS, o.worldNormal.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), o.sh, o.probeOcclusion); + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(o); + #endif + + o.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + if (!forceNoMotion) + { + #if defined(HAVE_VFX_MODIFICATION) + float3 previousPositionOS = currentFrameMvData.vfxParticlePositionOS; + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + const bool applyDeformation = false; + #else + const bool applyDeformation = true; + #endif + #else + const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation + float3 previousPositionOS = hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz; + + #if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT) + const bool applyDeformation = true; + #else + const bool applyDeformation = hasDeformation; + #endif + #endif + // TODO + #if defined(FEATURES_GRAPH_VERTEX) + if (applyDeformation) + previousPositionOS = GetLastFrameDeformedPosition(previousMesh, currentFrameMvData, previousPositionOS); + else + previousPositionOS = previousMesh.positionOS; + + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + #endif + + #if defined(UNITY_DOTS_INSTANCING_ENABLED) && defined(DOTS_DEFORMED) + // Deformed vertices in DOTS are not cumulative with built-in Unity skinning/blend shapes + // Needs to be called after vertex modification has been applied otherwise it will be + // overwritten by Compute Deform node + ApplyPreviousFrameDeformedVertexPosition(previousMesh.vertexID, previousPositionOS); + #endif + #if defined (_ADD_PRECOMPUTED_VELOCITY) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + o.positionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionWS, 1.0f)); + + #if defined(HAVE_VFX_MODIFICATION) + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) || defined(_ADD_PRECOMPUTED_VELOCITY) + #error Unexpected fast path rendering VFX motion vector while there are vertex modification afterwards. + #endif + o.previousPositionCS = VFXGetPreviousClipPosition(previousMesh, currentFrameMvData.vfxElementAttributes, o.positionCS); + #else + #if VFX_WORLD_SPACE + //previousPositionOS is already in world space + const float3 previousPositionWS = previousPositionOS; + #else + const float3 previousPositionWS = mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f)).xyz; + #endif + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionWS, 1.0f)); + #endif + #else + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1))); + #endif + } + #endif + + return o; + } + + + + +#if _UNLIT + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl" +#endif + + // fragment shader + void Frag (VertexToPixel IN + , out half4 outColor : SV_Target0 + #ifdef _WRITE_RENDERING_LAYERS + , out float4 outRenderingLayers : SV_Target1 + #endif + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if _USESPECULAR || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + + + InputData inputData = (InputData)0; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + +#if _BAKEDLIT + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = 0; +#else + inputData.fogCoord = InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x); + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; +#endif + + + + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #elif _BAKEDLIT + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #else + #if defined(DYNAMICLIGHTMAP_ON) + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS); + #elif defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2) + #if UNITY_VERSION >= 60000009 + inputData.bakedGI = SAMPLE_GI(IN.sh, IN.worldPos, inputData.normalWS, inputData.viewDirectionWS, IN.pos, IN.probeOcclusion, inputData.shadowMask); + #else + inputData.bakedGI = SAMPLE_GI(IN.sh, IN.worldPos, inputData.normalWS, inputData.viewDirectionWS, IN.pos); + #endif + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + #endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos); + #if !_BAKEDLIT + inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector)); + inputData.shadowMask = mulColor; + #endif + #else + inputData.shadowMask = float4(1,1,1,1); + #endif + + #if defined(DEBUG_DISPLAY) + #if defined(DYNAMICLIGHTMAP_ON) + inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy; + #endif + #if defined(LIGHTMAP_ON) + inputData.staticLightmapUV = IN.lightmapUV; + #else + inputData.vertexSH = IN.sh; + #endif + #endif + + #if _WORLDSPACENORMAL + float3 normalTS = WorldToTangentSpace(d, l.Normal); + #else + float3 normalTS = l.Normal; + #endif + + SurfaceData surface = (SurfaceData)0; + surface.albedo = l.Albedo; + surface.metallic = saturate(metallic); + surface.specular = specular; + surface.smoothness = saturate(l.Smoothness), + surface.occlusion = l.Occlusion, + surface.emission = l.Emission, + surface.alpha = saturate(l.Alpha); + surface.clearCoatMask = 0; + surface.clearCoatSmoothness = 1; + + #ifdef _CLEARCOAT + surface.clearCoatMask = saturate(l.CoatMask); + surface.clearCoatSmoothness = saturate(l.CoatSmoothness); + #endif + + #if !_UNLIT + half4 color = half4(l.Albedo, l.Alpha); + #ifdef _DBUFFER + #if _BAKEDLIT + half3 bakeColor = color.rgb; + float3 bakeNormal = inputData.normalWS.xyz; + ApplyDecalToBaseColorAndNormal(IN.pos, bakeColor, bakeNormal); + color.rgb = bakeColor; + inputData.normalWS.xyz = bakeNormal; + #else + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + #endif + #if _SIMPLELIT + color = UniversalFragmentBlinnPhong( + inputData, + surface); + #elif _BAKEDLIT + color = UniversalFragmentBakedLit(inputData, color.rgb, color.a, normalTS); + #else + color = UniversalFragmentPBR(inputData, surface); + #endif + + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + + #else // unlit + #ifdef _DBUFFER + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + half4 color = UniversalFragmentUnlit(inputData, l.Albedo, l.Alpha); + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + #endif + ChainFinalColorForward(l, d, color); + + outColor = color; + + #ifdef _WRITE_RENDERING_LAYERS + #if UNITY_VERSION >= 60020000 + outRenderingLayers = EncodeMeshRenderingLayer(); + #else + uint renderingLayers = GetMeshRenderingLayer(); + outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0); + #endif + #endif + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float4 probeOcclusion : TEXCOORD8; + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float4 previousPositionCS : TEXCOORD21; // Contain previous transform position (in case of skinning for example) + float4 positionCS : TEXCOORD22; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #define GetWorldToViewMatrix() _ViewMatrix + #define UNITY_MATRIX_I_V _InvViewMatrix + #define GetViewToHClipMatrix() OptimizeProjectionMatrix(_ProjMatrix) + #define UNITY_MATRIX_I_P _InvProjMatrix + #define GetWorldToHClipMatrix() _ViewProjMatrix + #define UNITY_MATRIX_I_VP _InvViewProjMatrix + #define UNITY_MATRIX_UNJITTERED_VP _NonJitteredViewProjMatrix + #define UNITY_MATRIX_PREV_VP _PrevViewProjMatrix + #define UNITY_MATRIX_PREV_I_VP _PrevInvViewProjMatrix + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = v; + #endif + #if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); + #endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // This return the camera relative position (if enable) + float3 positionWS = TransformObjectToWorld(v.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(v.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = positionWS; + o.worldNormal = normalWS; + o.worldTangent = tangentWS; + + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + #if UNITY_VERSION < 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #if UNITY_VERSION >= 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + #elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && UNITY_VERSION >= 60000009 + OUTPUT_SH4(vertexInput.positionWS, o.worldNormal.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), o.sh, o.probeOcclusion); + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(o); + #endif + + o.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + if (!forceNoMotion) + { + #if defined(HAVE_VFX_MODIFICATION) + float3 previousPositionOS = currentFrameMvData.vfxParticlePositionOS; + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + const bool applyDeformation = false; + #else + const bool applyDeformation = true; + #endif + #else + const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation + float3 previousPositionOS = hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz; + + #if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT) + const bool applyDeformation = true; + #else + const bool applyDeformation = hasDeformation; + #endif + #endif + // TODO + #if defined(FEATURES_GRAPH_VERTEX) + if (applyDeformation) + previousPositionOS = GetLastFrameDeformedPosition(previousMesh, currentFrameMvData, previousPositionOS); + else + previousPositionOS = previousMesh.positionOS; + + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + #endif + + #if defined(UNITY_DOTS_INSTANCING_ENABLED) && defined(DOTS_DEFORMED) + // Deformed vertices in DOTS are not cumulative with built-in Unity skinning/blend shapes + // Needs to be called after vertex modification has been applied otherwise it will be + // overwritten by Compute Deform node + ApplyPreviousFrameDeformedVertexPosition(previousMesh.vertexID, previousPositionOS); + #endif + #if defined (_ADD_PRECOMPUTED_VELOCITY) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + o.positionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionWS, 1.0f)); + + #if defined(HAVE_VFX_MODIFICATION) + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) || defined(_ADD_PRECOMPUTED_VELOCITY) + #error Unexpected fast path rendering VFX motion vector while there are vertex modification afterwards. + #endif + o.previousPositionCS = VFXGetPreviousClipPosition(previousMesh, currentFrameMvData.vfxElementAttributes, o.positionCS); + #else + #if VFX_WORLD_SPACE + //previousPositionOS is already in world space + const float3 previousPositionWS = previousPositionOS; + #else + const float3 previousPositionWS = mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f)).xyz; + #endif + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionWS, 1.0f)); + #endif + #else + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1))); + #endif + } + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + + + } + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLit.shader.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLit.shader.meta new file mode 100644 index 0000000..d131fbf --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLit.shader.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: 86ce7e600deb17e429b8be445bb652f7 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLit.shader + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLitTransparent.shader b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLitTransparent.shader new file mode 100644 index 0000000..082441b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLitTransparent.shader @@ -0,0 +1,5252 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2023 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0 + [HideInInspector]_QueueControl("_QueueControl", Float) = -1 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Cull Back + Blend One Zero + ZTest LEqual + ZWrite On + + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + // Keywords + #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + #pragma multi_compile_fragment _ _SHADOWS_SOFT + #pragma multi_compile_fragment _ _SHADOWS_SOFT_LOW + #pragma multi_compile_fragment _ _SHADOWS_SOFT_MEDIUM + #pragma multi_compile_fragment _ _SHADOWS_SOFT_HIGH + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + //#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 + #pragma multi_compile_fragment _ _LIGHT_LAYERS + #pragma multi_compile_fragment _ DEBUG_DISPLAY + #pragma multi_compile_fragment _ _LIGHT_COOKIES + #pragma multi_compile _ _FORWARD_PLUS + #pragma multi_compile _ EVALUATE_SH_VERTEX + #pragma multi_compile _ EVALUATE_SH_MIXED + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + + // GraphKeywords: + + #define SHADER_PASS SHADERPASS_FORWARD + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define _PASSFORWARD 1 + #define _FOG_FRAGMENT 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float4 probeOcclusion : TEXCOORD8; + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float4 previousPositionCS : TEXCOORD21; // Contain previous transform position (in case of skinning for example) + float4 positionCS : TEXCOORD22; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #define GetWorldToViewMatrix() _ViewMatrix + #define UNITY_MATRIX_I_V _InvViewMatrix + #define GetViewToHClipMatrix() OptimizeProjectionMatrix(_ProjMatrix) + #define UNITY_MATRIX_I_P _InvProjMatrix + #define GetWorldToHClipMatrix() _ViewProjMatrix + #define UNITY_MATRIX_I_VP _InvViewProjMatrix + #define UNITY_MATRIX_UNJITTERED_VP _NonJitteredViewProjMatrix + #define UNITY_MATRIX_PREV_VP _PrevViewProjMatrix + #define UNITY_MATRIX_PREV_I_VP _PrevInvViewProjMatrix + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = v; + #endif + #if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); + #endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // This return the camera relative position (if enable) + float3 positionWS = TransformObjectToWorld(v.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(v.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = positionWS; + o.worldNormal = normalWS; + o.worldTangent = tangentWS; + + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + #if UNITY_VERSION < 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #if UNITY_VERSION >= 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + #elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && UNITY_VERSION >= 60000009 + OUTPUT_SH4(vertexInput.positionWS, o.worldNormal.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), o.sh, o.probeOcclusion); + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(o); + #endif + + o.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + if (!forceNoMotion) + { + #if defined(HAVE_VFX_MODIFICATION) + float3 previousPositionOS = currentFrameMvData.vfxParticlePositionOS; + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + const bool applyDeformation = false; + #else + const bool applyDeformation = true; + #endif + #else + const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation + float3 previousPositionOS = hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz; + + #if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT) + const bool applyDeformation = true; + #else + const bool applyDeformation = hasDeformation; + #endif + #endif + // TODO + #if defined(FEATURES_GRAPH_VERTEX) + if (applyDeformation) + previousPositionOS = GetLastFrameDeformedPosition(previousMesh, currentFrameMvData, previousPositionOS); + else + previousPositionOS = previousMesh.positionOS; + + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + #endif + + #if defined(UNITY_DOTS_INSTANCING_ENABLED) && defined(DOTS_DEFORMED) + // Deformed vertices in DOTS are not cumulative with built-in Unity skinning/blend shapes + // Needs to be called after vertex modification has been applied otherwise it will be + // overwritten by Compute Deform node + ApplyPreviousFrameDeformedVertexPosition(previousMesh.vertexID, previousPositionOS); + #endif + #if defined (_ADD_PRECOMPUTED_VELOCITY) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + o.positionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionWS, 1.0f)); + + #if defined(HAVE_VFX_MODIFICATION) + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) || defined(_ADD_PRECOMPUTED_VELOCITY) + #error Unexpected fast path rendering VFX motion vector while there are vertex modification afterwards. + #endif + o.previousPositionCS = VFXGetPreviousClipPosition(previousMesh, currentFrameMvData.vfxElementAttributes, o.positionCS); + #else + #if VFX_WORLD_SPACE + //previousPositionOS is already in world space + const float3 previousPositionWS = previousPositionOS; + #else + const float3 previousPositionWS = mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f)).xyz; + #endif + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionWS, 1.0f)); + #endif + #else + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1))); + #endif + } + #endif + + return o; + } + + + + +#if _UNLIT + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl" +#endif + + // fragment shader + void Frag (VertexToPixel IN + , out half4 outColor : SV_Target0 + #ifdef _WRITE_RENDERING_LAYERS + , out float4 outRenderingLayers : SV_Target1 + #endif + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if _USESPECULAR || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + + + InputData inputData = (InputData)0; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + +#if _BAKEDLIT + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = 0; +#else + inputData.fogCoord = InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x); + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; +#endif + + + + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #elif _BAKEDLIT + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #else + #if defined(DYNAMICLIGHTMAP_ON) + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS); + #elif defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2) + #if UNITY_VERSION >= 60000009 + inputData.bakedGI = SAMPLE_GI(IN.sh, IN.worldPos, inputData.normalWS, inputData.viewDirectionWS, IN.pos, IN.probeOcclusion, inputData.shadowMask); + #else + inputData.bakedGI = SAMPLE_GI(IN.sh, IN.worldPos, inputData.normalWS, inputData.viewDirectionWS, IN.pos); + #endif + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + #endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos); + #if !_BAKEDLIT + inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector)); + inputData.shadowMask = mulColor; + #endif + #else + inputData.shadowMask = float4(1,1,1,1); + #endif + + #if defined(DEBUG_DISPLAY) + #if defined(DYNAMICLIGHTMAP_ON) + inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy; + #endif + #if defined(LIGHTMAP_ON) + inputData.staticLightmapUV = IN.lightmapUV; + #else + inputData.vertexSH = IN.sh; + #endif + #endif + + #if _WORLDSPACENORMAL + float3 normalTS = WorldToTangentSpace(d, l.Normal); + #else + float3 normalTS = l.Normal; + #endif + + SurfaceData surface = (SurfaceData)0; + surface.albedo = l.Albedo; + surface.metallic = saturate(metallic); + surface.specular = specular; + surface.smoothness = saturate(l.Smoothness), + surface.occlusion = l.Occlusion, + surface.emission = l.Emission, + surface.alpha = saturate(l.Alpha); + surface.clearCoatMask = 0; + surface.clearCoatSmoothness = 1; + + #ifdef _CLEARCOAT + surface.clearCoatMask = saturate(l.CoatMask); + surface.clearCoatSmoothness = saturate(l.CoatSmoothness); + #endif + + #if !_UNLIT + half4 color = half4(l.Albedo, l.Alpha); + #ifdef _DBUFFER + #if _BAKEDLIT + half3 bakeColor = color.rgb; + float3 bakeNormal = inputData.normalWS.xyz; + ApplyDecalToBaseColorAndNormal(IN.pos, bakeColor, bakeNormal); + color.rgb = bakeColor; + inputData.normalWS.xyz = bakeNormal; + #else + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + #endif + #if _SIMPLELIT + color = UniversalFragmentBlinnPhong( + inputData, + surface); + #elif _BAKEDLIT + color = UniversalFragmentBakedLit(inputData, color.rgb, color.a, normalTS); + #else + color = UniversalFragmentPBR(inputData, surface); + #endif + + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + + #else // unlit + #ifdef _DBUFFER + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + half4 color = UniversalFragmentUnlit(inputData, l.Albedo, l.Alpha); + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + #endif + ChainFinalColorForward(l, d, color); + + outColor = color; + + #ifdef _WRITE_RENDERING_LAYERS + #if UNITY_VERSION >= 60020000 + outRenderingLayers = EncodeMeshRenderingLayer(); + #else + uint renderingLayers = GetMeshRenderingLayer(); + outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0); + #endif + #endif + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float4 probeOcclusion : TEXCOORD8; + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float4 previousPositionCS : TEXCOORD21; // Contain previous transform position (in case of skinning for example) + float4 positionCS : TEXCOORD22; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #define GetWorldToViewMatrix() _ViewMatrix + #define UNITY_MATRIX_I_V _InvViewMatrix + #define GetViewToHClipMatrix() OptimizeProjectionMatrix(_ProjMatrix) + #define UNITY_MATRIX_I_P _InvProjMatrix + #define GetWorldToHClipMatrix() _ViewProjMatrix + #define UNITY_MATRIX_I_VP _InvViewProjMatrix + #define UNITY_MATRIX_UNJITTERED_VP _NonJitteredViewProjMatrix + #define UNITY_MATRIX_PREV_VP _PrevViewProjMatrix + #define UNITY_MATRIX_PREV_I_VP _PrevInvViewProjMatrix + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = v; + #endif + #if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); + #endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // This return the camera relative position (if enable) + float3 positionWS = TransformObjectToWorld(v.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(v.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = positionWS; + o.worldNormal = normalWS; + o.worldTangent = tangentWS; + + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + #if UNITY_VERSION < 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #if UNITY_VERSION >= 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + #elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && UNITY_VERSION >= 60000009 + OUTPUT_SH4(vertexInput.positionWS, o.worldNormal.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), o.sh, o.probeOcclusion); + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(o); + #endif + + o.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + if (!forceNoMotion) + { + #if defined(HAVE_VFX_MODIFICATION) + float3 previousPositionOS = currentFrameMvData.vfxParticlePositionOS; + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + const bool applyDeformation = false; + #else + const bool applyDeformation = true; + #endif + #else + const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation + float3 previousPositionOS = hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz; + + #if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT) + const bool applyDeformation = true; + #else + const bool applyDeformation = hasDeformation; + #endif + #endif + // TODO + #if defined(FEATURES_GRAPH_VERTEX) + if (applyDeformation) + previousPositionOS = GetLastFrameDeformedPosition(previousMesh, currentFrameMvData, previousPositionOS); + else + previousPositionOS = previousMesh.positionOS; + + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + #endif + + #if defined(UNITY_DOTS_INSTANCING_ENABLED) && defined(DOTS_DEFORMED) + // Deformed vertices in DOTS are not cumulative with built-in Unity skinning/blend shapes + // Needs to be called after vertex modification has been applied otherwise it will be + // overwritten by Compute Deform node + ApplyPreviousFrameDeformedVertexPosition(previousMesh.vertexID, previousPositionOS); + #endif + #if defined (_ADD_PRECOMPUTED_VELOCITY) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + o.positionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionWS, 1.0f)); + + #if defined(HAVE_VFX_MODIFICATION) + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) || defined(_ADD_PRECOMPUTED_VELOCITY) + #error Unexpected fast path rendering VFX motion vector while there are vertex modification afterwards. + #endif + o.previousPositionCS = VFXGetPreviousClipPosition(previousMesh, currentFrameMvData.vfxElementAttributes, o.positionCS); + #else + #if VFX_WORLD_SPACE + //previousPositionOS is already in world space + const float3 previousPositionWS = previousPositionOS; + #else + const float3 previousPositionWS = mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f)).xyz; + #endif + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionWS, 1.0f)); + #endif + #else + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1))); + #endif + } + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + + + } + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLitTransparent.shader.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLitTransparent.shader.meta new file mode 100644 index 0000000..1151eda --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLitTransparent.shader.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: 4cab4aa8ce3e6774aa0d904ec70df88e +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderLitTransparent.shader + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderSRPBatch.shader b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderSRPBatch.shader new file mode 100644 index 0000000..8ab45dd --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderSRPBatch.shader @@ -0,0 +1,350 @@ +Shader "AllIn1SpriteShader/AllIn1SpriteShaderSRPBatch" +{ + Properties + { + [NoScaleOffset]_MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset]_FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + [NoScaleOffset]_FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + [NoScaleOffset]_OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset]_OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset]_DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 0.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset]_OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //179 + + _ZTestMode ("Z Test Mode", Float) = 4 + _CullingOption ("Culling Option", float) = 0 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 + _EditorDrawers("Editor Drawers", Int) = 6 + } + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.high-definition" : "12.1" + } + + Tags { "Queue" = "Transparent" "CanUseSpriteAtlas" = "True" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" } + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + Pass + { + HLSLPROGRAM + #pragma target 4.5 + #pragma multi_compile_instancing + #pragma vertex vert + #pragma fragment frag + + #define HDRP_PASS + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl" + + #include "ShaderLibrary/AllIn1SpriteShaderSRP_CommonFunctions.hlsl" + #include "ShaderLibrary/AllIn1SpriteShaderSRP_HDRPHelper.hlsl" + + #include "ShaderLibrary/AllIn1SpriteShaderSRP_Structs.hlsl" + #include_with_pragmas "ShaderLibrary/AllIn1SpriteShaderSRP_ShaderFeatures.hlsl" + #include "ShaderLibrary/AllIn1SpriteShaderSRP_Properties.hlsl" + #include "ShaderLibrary/AllIn1SpriteShaderSRP_VertexPass.hlsl" + #include "ShaderLibrary/AllIn1SpriteShaderSRP_FragmentPass.hlsl" + + + + #if FOG_ON + #pragma multi_compile_fog + #endif + + ENDHLSL + } + } + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "12.0" + } + + Tags { "Queue" = "Transparent" "CanUseSpriteAtlas" = "True" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" } + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + Pass + { + HLSLPROGRAM + #pragma multi_compile_instancing + #pragma vertex vert + #pragma fragment frag + + #define URP_PASS + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + + #include "ShaderLibrary/AllIn1SpriteShaderSRP_CommonFunctions.hlsl" + #include "ShaderLibrary/AllIn1SpriteShaderSRP_URPHelper.hlsl" + + #include "ShaderLibrary/AllIn1SpriteShaderSRP_Structs.hlsl" + #include_with_pragmas "ShaderLibrary/AllIn1SpriteShaderSRP_ShaderFeatures.hlsl" + #include "ShaderLibrary/AllIn1SpriteShaderSRP_Properties.hlsl" + #include "ShaderLibrary/AllIn1SpriteShaderSRP_VertexPass.hlsl" + #include "ShaderLibrary/AllIn1SpriteShaderSRP_FragmentPass.hlsl" + + + + #if FOG_ON + #pragma multi_compile_fog + #endif + + ENDHLSL + } + } + + //Fallback "AllIn1SpriteShader/AllIn1SpriteShader" + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderMaterialInspector" +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderSRPBatch.shader.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderSRPBatch.shader.meta new file mode 100644 index 0000000..d7a8dcc --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderSRPBatch.shader.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: 7e09cd2cd29cb3c45b69adf230c51ae0 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderSRPBatch.shader + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderScaledTime.shader b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderScaledTime.shader new file mode 100644 index 0000000..6f60544 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderScaledTime.shader @@ -0,0 +1,1236 @@ +Shader "AllIn1SpriteShader/AllIn1SpriteShaderScaledTime" +{ + Properties + { + _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 0.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //172 + + _ZTestMode ("Z Test Mode", Float) = 4 + _CullingOption ("Culling Option", float) = 0 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 + _EditorDrawers("Editor Drawers", Int) = 6 + } + + SubShader + { + Tags { "Queue" = "Transparent" "CanUseSpriteAtlas" = "True" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" } + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_instancing + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local ALPHACUTOFF_ON + #pragma shader_feature_local ALPHAROUND_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature ATLAS_ON + #pragma shader_feature PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + #pragma shader_feature FOG_ON + + #include "UnityCG.cginc" + #include "AllIn1OneShaderFunctions.cginc" + + #if FOG_ON + #pragma multi_compile_fog + #endif + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half4 color : COLOR; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + half4 color : COLOR; + #if OUTTEX_ON + half2 uvOutTex : TEXCOORD1; + #endif + #if OUTDIST_ON + half2 uvOutDistTex : TEXCOORD2; + #endif + #if DISTORT_ON + half2 uvDistTex : TEXCOORD3; + #endif + #if FOG_ON + UNITY_FOG_COORDS(4) + #endif + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + float globalUnscaledTime; + + sampler2D _MainTex; + half4 _MainTex_ST, _MainTex_TexelSize, _Color; + half _Alpha; + + #if ATLAS_ON + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + #endif + + #if RECTSIZE_ON + half _RectSize; + #endif + + #if OFFSETUV_ON + half _OffsetUvX, _OffsetUvY; + #endif + + #if CLIPPING_ON + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + #endif + + #if RADIALCLIPPING_ON + half _RadialStartAngle, _RadialClip, _RadialClip2; + #endif + + #if TWISTUV_ON + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + #endif + + #if ROTATEUV_ON + half _RotateUvAmount; + #endif + + #if FISHEYE_ON + half _FishEyeUvAmount; + #endif + + #if PINCH_ON + half _PinchUvAmount; + #endif + + #if DOODLE_ON + half _HandDrawnAmount, _HandDrawnSpeed; + #endif + + #if SHAKEUV_ON + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + #endif + + #if WAVEUV_ON + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + #endif + + #if ROUNDWAVEUV_ON + half _RoundWaveStrength, _RoundWaveSpeed; + #endif + + #if ZOOMUV_ON + half _ZoomUvAmount; + #endif + + #if FADE_ON + sampler2D _FadeTex, _FadeBurnTex; + half4 _FadeBurnColor, _FadeTex_ST, _FadeBurnTex_ST; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + #endif + + #if TEXTURESCROLL_ON + half _TextureScrollXSpeed, _TextureScrollYSpeed; + #endif + + #if GLOW_ON + sampler2D _GlowTex; + half4 _GlowColor; + half _Glow, _GlowGlobal; + #endif + + #if OUTBASE_ON + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + #endif + + #if OUTTEX_ON + sampler2D _OutlineTex; + half4 _OutlineTex_ST; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + #endif + + #if OUTDIST_ON + sampler2D _OutlineDistortTex; + half4 _OutlineDistortTex_ST; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + #endif + + #if DISTORT_ON + sampler2D _DistortTex; + half4 _DistortTex_ST; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + #endif + + #if WARP_ON + half _WarpStrength, _WarpSpeed, _WarpScale; + #endif + + #if WIND_ON + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + #endif + + #if GRADIENT_ON + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + #endif + + #if COLORSWAP_ON + sampler2D _ColorSwapTex; + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + #endif + + #if HSV_ON + half _HsvShift, _HsvSaturation, _HsvBright; + #endif + + #if HITEFFECT_ON + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + #endif + + #if PIXELATE_ON + half _PixelateSize; + #endif + + #if NEGATIVE_ON + half _NegativeAmount; + #endif + + #if COLORRAMP_ON + sampler2D _ColorRampTex, _ColorRampTexGradient; + half _ColorRampLuminosity, _ColorRampBlend; + #endif + + #if GREYSCALE_ON + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + #endif + + #if POSTERIZE_ON + half _PosterizeNumColors, _PosterizeGamma; + #endif + + #if BLUR_ON + half _BlurIntensity; + #endif + + #if MOTIONBLUR_ON + half _MotionBlurAngle, _MotionBlurDist; + #endif + + #if GHOST_ON + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + #endif + + #if ALPHAOUTLINE_ON + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + #endif + + #if INNEROUTLINE_ON + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + #endif + + #if HOLOGRAM_ON + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + #endif + + #if CHROMABERR_ON + half _ChromAberrAmount, _ChromAberrAlpha; + #endif + + #if GLITCH_ON + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + #endif + + #if FLICKER_ON + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + #endif + + #if SHADOW_ON + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + #endif + + #if SHINE_ON + sampler2D _ShineMask; + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + #endif + + #if ALPHACUTOFF_ON + half _AlphaCutoffValue; + #endif + + #if ALPHAROUND_ON + half _AlphaRoundThreshold; + #endif + + #if CHANGECOLOR_ON + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + #endif + #if CHANGECOLOR2_ON + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + #endif + #if CHANGECOLOR3_ON + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + #endif + + #if CONTRAST_ON + half _Contrast, _Brightness; + #endif + + #if OVERLAY_ON + sampler2D _OverlayTex; + half4 _OverlayTex_ST, _OverlayColor; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + #endif + + UNITY_INSTANCING_BUFFER_START(Props) + UNITY_DEFINE_INSTANCED_PROP(float, _RandomSeed) + UNITY_INSTANCING_BUFFER_END(Props) + + v2f vert (appdata v) + { + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + half3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + o.vertex = UnityObjectToClipPos(half4(localPos, 1)); + #else + o.vertex = UnityObjectToClipPos(v.vertex); + #endif + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.color = v.color; + + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + #if POLARUV_ON + o.uv = v.uv - center; + #endif + + #if ROTATEUV_ON + half2 uvC = v.uv; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + o.uv = mul(rot, uvC); + o.uv += center; + #endif + + #if OUTTEX_ON + o.uvOutTex = TRANSFORM_TEX(v.uv, _OutlineTex); + #endif + + #if OUTDIST_ON + o.uvOutDistTex = TRANSFORM_TEX(v.uv, _OutlineDistortTex); + #endif + + #if DISTORT_ON + o.uvDistTex = TRANSFORM_TEX(v.uv, _DistortTex); + #endif + + #if FOG_ON + UNITY_TRANSFER_FOG(o,o.vertex); + #endif + + return o; + } + + half3 GetPixel(in int offsetX, in int offsetY, half2 uv, sampler2D tex) + { + return tex2D(tex, (uv + half2(offsetX * _MainTex_TexelSize.x, offsetY * _MainTex_TexelSize.y))).rgb; + } + + half4 frag (v2f i) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + half randomSeed = UNITY_ACCESS_INSTANCED_PROP(Props, _RandomSeed); + + float2 uvRect = i.uv; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((i.uv.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ST.x, center.y * _MainTex_ST.y); + + #if CLIPPING_ON + half2 tiledUv = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + #if TEXTURESCROLL_ON && ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((((globalUnscaledTime * 20) + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs((((globalUnscaledTime * 20) + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + + #if OFFSETUV_ON + #if ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + i.uv += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + #if POLARUV_ON + i.uv = half2(atan2(i.uv.y, i.uv.x) / (2.0f * 3.141592653589f), length(i.uv)); + i.uv *= _MainTex_ST.xy; + #endif + + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = i.uv - half2(_TwistUvPosX * _MainTex_ST.x, _TwistUvPosY * _MainTex_ST.y); + _TwistUvRadius *= (_MainTex_ST.x + _MainTex_ST.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ST.x, _TwistUvPosY * _MainTex_ST.y); + i.uv = tempUv; + #endif + + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = i.uv - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + i.uv = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + + #if PINCH_ON + half2 dP = i.uv - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + i.uv = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + #if ZOOMUV_ON + i.uv -= centerTiled; + i.uv = i.uv * _ZoomUvAmount; + i.uv += centerTiled; + #endif + + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor(((globalUnscaledTime * 20) + randomSeed) * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + i.uv = lerp(i.uv, i.uv + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + #if SHAKEUV_ON + half xShake = sin((globalUnscaledTime + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((globalUnscaledTime + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + i.uv += half2(xShake * 0.012, yShake * 0.01); + #endif + + #if RECTSIZE_ON + i.uv = i.uv.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + #if DISTORT_ON + #if ATLAS_ON + i.uvDistTex.x = i.uvDistTex.x * (1 / (_MaxXUV - _MinXUV)); + i.uvDistTex.y = i.uvDistTex.y * (1 / (_MaxYUV - _MinYUV)); + #endif + i.uvDistTex.x += ((globalUnscaledTime + randomSeed) * _DistortTexXSpeed) % 1; + i.uvDistTex.y += ((globalUnscaledTime + randomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (tex2D(_DistortTex, i.uvDistTex).r - 0.5) * 0.2 * _DistortAmount; + i.uv.x += distortAmnt; + i.uv.y += distortAmnt; + #endif + + #if WARP_ON + half2 warpUv = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = ((globalUnscaledTime * 20) + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = ((globalUnscaledTime * 20) + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + i.uv += warp; + #endif + + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ST.x, _WaveY * _MainTex_ST.y) - i.uv; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = (globalUnscaledTime * 20) + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + i.uv = i.uv + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ST.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ST.y) - uvRect.y) * (_MainTex_TexelSize.w / _MainTex_TexelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + i.uv += (sin((ripple + ((globalUnscaledTime * 20) + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + + #if WIND_ON + half windOffset = sin((globalUnscaledTime + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = i.uv - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + i.uv = i.uv + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + #if TEXTURESCROLL_ON && !ATLAS_ON + i.uv.x += (((globalUnscaledTime * 20) + randomSeed) * _TextureScrollXSpeed) % 1; + i.uv.y += (((globalUnscaledTime * 20) + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + + #if PIXELATE_ON + half aspectRatio = _MainTex_TexelSize.x / _MainTex_TexelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + i.uv = floor(i.uv * pixelSize) / pixelSize; + #endif + + half4 col = tex2D(_MainTex, i.uv); + half originalAlpha = col.a; + col *= i.color; + #if PREMULTIPLYALPHA_ON + col.rgb *= col.a; + #endif + + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2CustomTime(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, globalUnscaledTime, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2CustomTime(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, globalUnscaledTime, _GlitchSpeed), 3.0); + col = tex2D(_MainTex, i.uv + half2(lineNoise * 0.02 * rand2CustomTime(half2(2.0, 1), randomSeed, globalUnscaledTime, _GlitchSpeed), 0)) * i.color; + #endif + + #if CHROMABERR_ON + half4 r = tex2D(_MainTex, i.uv + half2(_ChromAberrAmount/10, 0)) * i.color; + half4 b = tex2D(_MainTex, i.uv + half2(-_ChromAberrAmount/10, 0)) * i.color; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * i.color; + #else + col = Blur(i.uv, _MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * i.color; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, _BlurIntensity, 1, 1) * i.color; + #else + col = Blur(i.uv, _MainTex, _BlurIntensity) * i.color; + #endif + #endif + #endif + + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + half luminance = 0; + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + + #if INNEROUTLINE_ON + half3 innerT = abs(GetPixel(0, _InnerOutlineThickness, i.uv, _MainTex) - GetPixel(0, -_InnerOutlineThickness, i.uv, _MainTex)); + innerT += abs(GetPixel(_InnerOutlineThickness, 0, i.uv, _MainTex) - GetPixel(-_InnerOutlineThickness, 0, i.uv, _MainTex)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ST.x, uvRect.y / _MainTex_ST.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (_MainTex_TexelSize.w / _MainTex_TexelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = tex2D(_ColorSwapTex, i.uv); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, tex2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, tex2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + + #if CHANGECOLOR_ON + float3 currChangeColor = col.rgb; + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + + #if OVERLAY_ON + half2 overlayUvs = uvRect; + overlayUvs.x += (((globalUnscaledTime * 20) + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += (((globalUnscaledTime * 20) + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = tex2D(_OverlayTex, TRANSFORM_TEX(overlayUvs, _OverlayTex)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //OUTLINE------------------------------------------------------------- + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * _MainTex_TexelSize.x, _OutlinePixelWidth * _MainTex_TexelSize.y); + #else + half2 destUv = half2(_OutlineWidth * _MainTex_TexelSize.x * 200, _OutlineWidth * _MainTex_TexelSize.y * 200); + #endif + + #if OUTDIST_ON + half2 uvOutDist = uvRect; + uvOutDist.x += ((globalUnscaledTime + randomSeed) * _OutlineDistortTexXSpeed) % 1; + uvOutDist.y += ((globalUnscaledTime + randomSeed) * _OutlineDistortTexYSpeed) % 1; + half outDistortAmnt = (tex2D(_OutlineDistortTex, TRANSFORM_TEX(uvOutDist, _OutlineDistortTex)).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = tex2D(_MainTex, i.uv + half2(destUv.x, 0)).a; + half spriteRight = tex2D(_MainTex, i.uv - half2(destUv.x, 0)).a; + half spriteBottom = tex2D(_MainTex, i.uv + half2(0, destUv.y)).a; + half spriteTop = tex2D(_MainTex, i.uv - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = tex2D(_MainTex, i.uv + half2(destUv.x, destUv.y)).a; + half spriteTopRight = tex2D(_MainTex, i.uv + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = tex2D(_MainTex, i.uv + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = tex2D(_MainTex, i.uv + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + i.uvOutTex.x += ((globalUnscaledTime + randomSeed) * _OutlineTexXSpeed) % 1; + i.uvOutTex.y += ((globalUnscaledTime + randomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + i.uvOutTex = half2((i.uvOutTex.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uvOutTex.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = tex2D(_OutlineTex, i.uvOutTex); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * i.color.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //----------------------------------------------------------------------------- + + #if FADE_ON + half2 tiledUvFade1= TRANSFORM_TEX(i.uv, _FadeTex); + half2 tiledUvFade2 = TRANSFORM_TEX(i.uv, _FadeBurnTex); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = tex2D(_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * tex2D(_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + + #if SHADOW_ON + half shadowA = tex2D(_MainTex, i.uv + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * i.color.a, col.a); + #endif + + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = tex2D(_GlowTex, i.uv); + #else + emission = col; + #endif + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, tex2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, tex2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = tex2D(_ShineMask, i.uv).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((globalUnscaledTime + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + ((globalUnscaledTime * 60) + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + + col.a *= _Alpha; + + #if ALPHACUTOFF_ON + clip((1 - _AlphaCutoffValue) - (1 - col.a) - 0.01); + #endif + + #if ALPHAROUND_ON + col.a = step(_AlphaRoundThreshold, col.a); + #endif + + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + + col *= _Color; + + #if FOG_ON + UNITY_APPLY_FOG(i.fogCoord, col); + #endif + + return col; + } + ENDCG + } + } + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderMaterialInspector" + //Fallback "Sprites/Default" //Remove fallback so that any shader error is obvious to the user +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderScaledTime.shader.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderScaledTime.shader.meta new file mode 100644 index 0000000..9b293a4 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderScaledTime.shader.meta @@ -0,0 +1,29 @@ +fileFormatVersion: 2 +guid: f3622b3ac1631ea409b0f5811034f3a9 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _GlowTex: {instanceID: 0} + - _FadeTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + - _FadeBurnTex: {fileID: 2800000, guid: 677cca399782dea41aedc1d292ecb67d, type: 3} + - _OutlineTex: {fileID: 2800000, guid: 74087f6d03f233e4a8a142fa01f9e5cf, type: 3} + - _OutlineDistortTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, + type: 3} + - _ColorSwapTex: {instanceID: 0} + - _ColorRampTex: {fileID: 2800000, guid: 279657edc397ece4b8029c727adf6ddc, type: 3} + - _DistortTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + - _ShineMask: {instanceID: 0} + - _ColorRampTexGradient: {instanceID: 0} + - _OverlayTex: {fileID: 2800000, guid: 677cca399782dea41aedc1d292ecb67d, type: 3} + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderScaledTime.shader + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMask.shader b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMask.shader new file mode 100644 index 0000000..855a165 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMask.shader @@ -0,0 +1,1247 @@ +Shader "AllIn1SpriteShader/AllIn1SpriteShaderUiMask" +{ + Properties + { + _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 0.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //172 + + _Stencil ("Stencil ID", Float) = 0 + _StencilComp ("Stencil Comparison", Float) = 8 + _StencilOp ("Stencil Operation", Float) = 0 + _StencilWriteMask ("Stencil Write Mask", Float) = 255 + _StencilReadMask ("Stencil Read Mask", Float) = 255 + _ColorMask ("Color Mask", Float) = 15 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 + _EditorDrawers("Editor Drawers", Int) = 6 + } + + SubShader + { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" } + Blend [_MySrcMode] [_MyDstMode] + Cull Off + ZWrite Off + ZTest [unity_GUIZTestMode] + ColorMask [_ColorMask] + + Stencil + { + Ref [_Stencil] + Comp [_StencilComp] + Pass [_StencilOp] + ReadMask [_StencilReadMask] + WriteMask [_StencilWriteMask] + } + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_instancing + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local ALPHACUTOFF_ON + #pragma shader_feature_local ALPHAROUND_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature ATLAS_ON + #pragma shader_feature PREMULTIPLYALPHA_ON + + #pragma multi_compile _ UNITY_UI_CLIP_RECT + #pragma multi_compile _ UNITY_UI_ALPHACLIP + + #include "UnityCG.cginc" + #include "AllIn1OneShaderFunctions.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half4 color : COLOR; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + half4 color : COLOR; + #if OUTTEX_ON + half2 uvOutTex : TEXCOORD1; + #endif + #if OUTDIST_ON + half2 uvOutDistTex : TEXCOORD2; + #endif + #if DISTORT_ON + half2 uvDistTex : TEXCOORD3; + #endif + #if UNITY_UI_CLIP_RECT + half4 mask : TEXCOORD4; + #endif + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + #if UNITY_UI_CLIP_RECT + float4 _ClipRect; + half _UIMaskSoftnessX, _UIMaskSoftnessY; + #endif + + sampler2D _MainTex; + half4 _MainTex_ST, _MainTex_TexelSize, _Color; + half _Alpha; + + #if ATLAS_ON + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + #endif + + #if RECTSIZE_ON + half _RectSize; + #endif + + #if OFFSETUV_ON + half _OffsetUvX, _OffsetUvY; + #endif + + #if CLIPPING_ON + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + #endif + + #if RADIALCLIPPING_ON + half _RadialStartAngle, _RadialClip, _RadialClip2; + #endif + + #if TWISTUV_ON + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + #endif + + #if ROTATEUV_ON + half _RotateUvAmount; + #endif + + #if FISHEYE_ON + half _FishEyeUvAmount; + #endif + + #if PINCH_ON + half _PinchUvAmount; + #endif + + #if DOODLE_ON + half _HandDrawnAmount, _HandDrawnSpeed; + #endif + + #if SHAKEUV_ON + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + #endif + + #if WAVEUV_ON + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + #endif + + #if ROUNDWAVEUV_ON + half _RoundWaveStrength, _RoundWaveSpeed; + #endif + + #if ZOOMUV_ON + half _ZoomUvAmount; + #endif + + #if FADE_ON + sampler2D _FadeTex, _FadeBurnTex; + half4 _FadeBurnColor, _FadeTex_ST, _FadeBurnTex_ST; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + #endif + + #if TEXTURESCROLL_ON + half _TextureScrollXSpeed, _TextureScrollYSpeed; + #endif + + #if GLOW_ON + sampler2D _GlowTex; + half4 _GlowColor; + half _Glow, _GlowGlobal; + #endif + + #if OUTBASE_ON + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + #endif + + #if OUTTEX_ON + sampler2D _OutlineTex; + half4 _OutlineTex_ST; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + #endif + + #if OUTDIST_ON + sampler2D _OutlineDistortTex; + half4 _OutlineDistortTex_ST; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + #endif + + #if DISTORT_ON + sampler2D _DistortTex; + half4 _DistortTex_ST; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + #endif + + #if WARP_ON + half _WarpStrength, _WarpSpeed, _WarpScale; + #endif + + #if WIND_ON + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + #endif + + #if GRADIENT_ON + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + #endif + + #if COLORSWAP_ON + sampler2D _ColorSwapTex; + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + #endif + + #if HSV_ON + half _HsvShift, _HsvSaturation, _HsvBright; + #endif + + #if HITEFFECT_ON + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + #endif + + #if PIXELATE_ON + half _PixelateSize; + #endif + + #if NEGATIVE_ON + half _NegativeAmount; + #endif + + #if COLORRAMP_ON + sampler2D _ColorRampTex, _ColorRampTexGradient; + half _ColorRampLuminosity, _ColorRampBlend; + #endif + + #if GREYSCALE_ON + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + #endif + + #if POSTERIZE_ON + half _PosterizeNumColors, _PosterizeGamma; + #endif + + #if BLUR_ON + half _BlurIntensity; + #endif + + #if MOTIONBLUR_ON + half _MotionBlurAngle, _MotionBlurDist; + #endif + + #if GHOST_ON + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + #endif + + #if ALPHAOUTLINE_ON + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + #endif + + #if INNEROUTLINE_ON + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + #endif + + #if HOLOGRAM_ON + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + #endif + + #if CHROMABERR_ON + half _ChromAberrAmount, _ChromAberrAlpha; + #endif + + #if GLITCH_ON + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + #endif + + #if FLICKER_ON + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + #endif + + #if SHADOW_ON + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + #endif + + #if SHINE_ON + sampler2D _ShineMask; + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + #endif + + #if ALPHACUTOFF_ON + half _AlphaCutoffValue; + #endif + + #if ALPHAROUND_ON + half _AlphaRoundThreshold; + #endif + + #if CHANGECOLOR_ON + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + #endif + #if CHANGECOLOR2_ON + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + #endif + #if CHANGECOLOR3_ON + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + #endif + + #if CONTRAST_ON + half _Contrast, _Brightness; + #endif + + #if OVERLAY_ON + sampler2D _OverlayTex; + half4 _OverlayTex_ST, _OverlayColor; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + #endif + + UNITY_INSTANCING_BUFFER_START(Props) + UNITY_DEFINE_INSTANCED_PROP(float, _RandomSeed) + UNITY_INSTANCING_BUFFER_END(Props) + + v2f vert(appdata v) + { + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.color = v.color; + + #if UNITY_UI_CLIP_RECT + half2 pixelSize = o.vertex.w; + pixelSize /= half2(1, 1) * abs(mul((half2x2)UNITY_MATRIX_P, _ScreenParams.xy)); + half4 clampedRect = clamp(_ClipRect, -2e10, 2e10); + half2 maskUV = (v.vertex.xy - clampedRect.xy) / (clampedRect.zw - clampedRect.xy); + o.mask = half4(v.vertex.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_UIMaskSoftnessX, _UIMaskSoftnessY) + abs(pixelSize.xy))); + #endif + + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + #if POLARUV_ON + o.uv = v.uv - center; + #endif + + #if ROTATEUV_ON + half2 uvC = v.uv; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + o.uv = mul(rot, uvC); + o.uv += center; + #endif + + #if OUTTEX_ON + o.uvOutTex = TRANSFORM_TEX(v.uv, _OutlineTex); + #endif + + #if OUTDIST_ON + o.uvOutDistTex = TRANSFORM_TEX(v.uv, _OutlineDistortTex); + #endif + + #if DISTORT_ON + o.uvDistTex = TRANSFORM_TEX(v.uv, _DistortTex); + #endif + + return o; + } + + half3 GetPixel(in int offsetX, in int offsetY, half2 uv, sampler2D tex) + { + return tex2D(tex, (uv + half2(offsetX * _MainTex_TexelSize.x, offsetY * _MainTex_TexelSize.y))).rgb; + } + + half4 frag(v2f i) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + half randomSeed = UNITY_ACCESS_INSTANCED_PROP(Props, _RandomSeed); + + float2 uvRect = i.uv; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((i.uv.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ST.x, center.y * _MainTex_ST.y); + + #if CLIPPING_ON + half2 tiledUv = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + #if TEXTURESCROLL_ON && ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + + #if OFFSETUV_ON + #if ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + i.uv += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + #if POLARUV_ON + i.uv = half2(atan2(i.uv.y, i.uv.x) / (2.0f * 3.141592653589f), length(i.uv)); + i.uv *= _MainTex_ST.xy; + #endif + + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = i.uv - half2(_TwistUvPosX * _MainTex_ST.x, _TwistUvPosY * _MainTex_ST.y); + _TwistUvRadius *= (_MainTex_ST.x + _MainTex_ST.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ST.x, _TwistUvPosY * _MainTex_ST.y); + i.uv = tempUv; + #endif + + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = i.uv - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + i.uv = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + + #if PINCH_ON + half2 dP = i.uv - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + i.uv = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + #if ZOOMUV_ON + i.uv -= centerTiled; + i.uv = i.uv * _ZoomUvAmount; + i.uv += centerTiled; + #endif + + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + i.uv = lerp(i.uv, i.uv + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + i.uv += half2(xShake * 0.012, yShake * 0.01); + #endif + + #if RECTSIZE_ON + i.uv = i.uv.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + #if DISTORT_ON + #if ATLAS_ON + i.uvDistTex.x = i.uvDistTex.x * (1 / (_MaxXUV - _MinXUV)); + i.uvDistTex.y = i.uvDistTex.y * (1 / (_MaxYUV - _MinYUV)); + #endif + i.uvDistTex.x += ((_Time.x + randomSeed) * _DistortTexXSpeed) % 1; + i.uvDistTex.y += ((_Time.x + randomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (tex2D(_DistortTex, i.uvDistTex).r - 0.5) * 0.2 * _DistortAmount; + i.uv.x += distortAmnt; + i.uv.y += distortAmnt; + #endif + + #if WARP_ON + half2 warpUv = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + i.uv += warp; + #endif + + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ST.x, _WaveY * _MainTex_ST.y) - i.uv; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + i.uv = i.uv + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ST.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ST.y) - uvRect.y) * (_MainTex_TexelSize.w / _MainTex_TexelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + i.uv += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = i.uv - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + i.uv = i.uv + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + #if TEXTURESCROLL_ON && !ATLAS_ON + i.uv.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + i.uv.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + + #if PIXELATE_ON + half aspectRatio = _MainTex_TexelSize.x / _MainTex_TexelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + i.uv = floor(i.uv * pixelSize) / pixelSize; + #endif + + half4 col = tex2D(_MainTex, i.uv); + half originalAlpha = col.a; + col *= i.color; + #if PREMULTIPLYALPHA_ON + col.rgb *= col.a; + #endif + + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = tex2D(_MainTex, i.uv + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * i.color; + #endif + + #if CHROMABERR_ON + half4 r = tex2D(_MainTex, i.uv + half2(_ChromAberrAmount/10, 0)) * i.color; + half4 b = tex2D(_MainTex, i.uv + half2(-_ChromAberrAmount/10, 0)) * i.color; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * i.color; + #else + col = Blur(i.uv, _MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * i.color; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, _BlurIntensity, 1, 1) * i.color; + #else + col = Blur(i.uv, _MainTex, _BlurIntensity) * i.color; + #endif + #endif + #endif + + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + half luminance = 0; + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + + #if INNEROUTLINE_ON + half3 innerT = abs(GetPixel(0, _InnerOutlineThickness, i.uv, _MainTex) - GetPixel(0, -_InnerOutlineThickness, i.uv, _MainTex)); + innerT += abs(GetPixel(_InnerOutlineThickness, 0, i.uv, _MainTex) - GetPixel(-_InnerOutlineThickness, 0, i.uv, _MainTex)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ST.x, uvRect.y / _MainTex_ST.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (_MainTex_TexelSize.w / _MainTex_TexelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = tex2D(_ColorSwapTex, i.uv); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, tex2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, tex2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + + #if OVERLAY_ON + half2 overlayUvs = uvRect; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = tex2D(_OverlayTex, TRANSFORM_TEX(overlayUvs, _OverlayTex)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //OUTLINE------------------------------------------------------------- + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * _MainTex_TexelSize.x, _OutlinePixelWidth * _MainTex_TexelSize.y); + #else + half2 destUv = half2(_OutlineWidth * _MainTex_TexelSize.x * 200, _OutlineWidth * _MainTex_TexelSize.y * 200); + #endif + + #if OUTDIST_ON + half2 uvOutDist = uvRect; + uvOutDist.x += ((_Time.x + randomSeed) * _OutlineDistortTexXSpeed) % 1; + uvOutDist.y += ((_Time.x + randomSeed) * _OutlineDistortTexYSpeed) % 1; + half outDistortAmnt = (tex2D(_OutlineDistortTex, TRANSFORM_TEX(uvOutDist, _OutlineDistortTex)).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = tex2D(_MainTex, i.uv + half2(destUv.x, 0)).a; + half spriteRight = tex2D(_MainTex, i.uv - half2(destUv.x, 0)).a; + half spriteBottom = tex2D(_MainTex, i.uv + half2(0, destUv.y)).a; + half spriteTop = tex2D(_MainTex, i.uv - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = tex2D(_MainTex, i.uv + half2(destUv.x, destUv.y)).a; + half spriteTopRight = tex2D(_MainTex, i.uv + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = tex2D(_MainTex, i.uv + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = tex2D(_MainTex, i.uv + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + i.uvOutTex.x += ((_Time.x + randomSeed) * _OutlineTexXSpeed) % 1; + i.uvOutTex.y += ((_Time.x + randomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + i.uvOutTex = half2((i.uvOutTex.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uvOutTex.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = tex2D(_OutlineTex, i.uvOutTex); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * i.color.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //----------------------------------------------------------------------------- + + #if FADE_ON + half2 tiledUvFade1= TRANSFORM_TEX(i.uv, _FadeTex); + half2 tiledUvFade2 = TRANSFORM_TEX(i.uv, _FadeBurnTex); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = tex2D(_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * tex2D(_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + + #if SHADOW_ON + half shadowA = tex2D(_MainTex, i.uv + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * i.color.a, col.a); + #endif + + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = tex2D(_GlowTex, i.uv); + #else + emission = col; + #endif + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, tex2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, tex2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = tex2D(_ShineMask, i.uv).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + + col.a *= _Alpha; + + #if UNITY_UI_CLIP_RECT + half2 clipMask = saturate((_ClipRect.zw - _ClipRect.xy - abs(i.mask.xy)) * i.mask.zw); + col.a *= clipMask.x * clipMask.y; + #endif + + #if UNITY_UI_ALPHACLIP + clip (col.a - 0.001); + #endif + + #if ALPHACUTOFF_ON + clip((1 - _AlphaCutoffValue) - (1 - col.a) - 0.01); + #endif + + #if ALPHAROUND_ON + col.a = step(_AlphaRoundThreshold, col.a); + #endif + + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + + col *= _Color; + + return col; + } + ENDCG + } + } + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderUiMaskMaterialInspector" + //Fallback "Sprites/Default" //Remove fallback so that any shader error is obvious to the user +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMask.shader.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMask.shader.meta new file mode 100644 index 0000000..38c77bc --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMask.shader.meta @@ -0,0 +1,29 @@ +fileFormatVersion: 2 +guid: a53f4bb29f3644b43b5075c6dcfecb32 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _GlowTex: {instanceID: 0} + - _FadeTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + - _FadeBurnTex: {fileID: 2800000, guid: 677cca399782dea41aedc1d292ecb67d, type: 3} + - _OutlineTex: {fileID: 2800000, guid: 74087f6d03f233e4a8a142fa01f9e5cf, type: 3} + - _OutlineDistortTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, + type: 3} + - _ColorSwapTex: {instanceID: 0} + - _ColorRampTex: {fileID: 2800000, guid: 279657edc397ece4b8029c727adf6ddc, type: 3} + - _DistortTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + - _ShineMask: {instanceID: 0} + - _ColorRampTexGradient: {instanceID: 0} + - _OverlayTex: {fileID: 2800000, guid: 677cca399782dea41aedc1d292ecb67d, type: 3} + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMask.shader + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMaskScaledTime.shader b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMaskScaledTime.shader new file mode 100644 index 0000000..d45c710 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMaskScaledTime.shader @@ -0,0 +1,1249 @@ +Shader "AllIn1SpriteShader/AllIn1SpriteShaderUiMaskScaledTime" +{ + Properties + { + _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 0.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //172 + + _Stencil ("Stencil ID", Float) = 0 + _StencilComp ("Stencil Comparison", Float) = 8 + _StencilOp ("Stencil Operation", Float) = 0 + _StencilWriteMask ("Stencil Write Mask", Float) = 255 + _StencilReadMask ("Stencil Read Mask", Float) = 255 + _ColorMask ("Color Mask", Float) = 15 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 + _EditorDrawers("Editor Drawers", Int) = 6 + } + + SubShader + { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" } + Blend [_MySrcMode] [_MyDstMode] + Cull Off + ZWrite Off + ZTest [unity_GUIZTestMode] + ColorMask [_ColorMask] + + Stencil + { + Ref [_Stencil] + Comp [_StencilComp] + Pass [_StencilOp] + ReadMask [_StencilReadMask] + WriteMask [_StencilWriteMask] + } + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_instancing + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local ALPHACUTOFF_ON + #pragma shader_feature_local ALPHAROUND_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature ATLAS_ON + #pragma shader_feature PREMULTIPLYALPHA_ON + + #pragma multi_compile _ UNITY_UI_CLIP_RECT + #pragma multi_compile _ UNITY_UI_ALPHACLIP + + #include "UnityCG.cginc" + #include "AllIn1OneShaderFunctions.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half4 color : COLOR; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + half4 color : COLOR; + #if OUTTEX_ON + half2 uvOutTex : TEXCOORD1; + #endif + #if OUTDIST_ON + half2 uvOutDistTex : TEXCOORD2; + #endif + #if DISTORT_ON + half2 uvDistTex : TEXCOORD3; + #endif + #if UNITY_UI_CLIP_RECT + half4 mask : TEXCOORD4; + #endif + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + #if UNITY_UI_CLIP_RECT + float4 _ClipRect; + half _UIMaskSoftnessX, _UIMaskSoftnessY; + #endif + + float globalUnscaledTime; + + sampler2D _MainTex; + half4 _MainTex_ST, _MainTex_TexelSize, _Color; + half _Alpha; + + #if ATLAS_ON + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + #endif + + #if RECTSIZE_ON + half _RectSize; + #endif + + #if OFFSETUV_ON + half _OffsetUvX, _OffsetUvY; + #endif + + #if CLIPPING_ON + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + #endif + + #if RADIALCLIPPING_ON + half _RadialStartAngle, _RadialClip, _RadialClip2; + #endif + + #if TWISTUV_ON + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + #endif + + #if ROTATEUV_ON + half _RotateUvAmount; + #endif + + #if FISHEYE_ON + half _FishEyeUvAmount; + #endif + + #if PINCH_ON + half _PinchUvAmount; + #endif + + #if DOODLE_ON + half _HandDrawnAmount, _HandDrawnSpeed; + #endif + + #if SHAKEUV_ON + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + #endif + + #if WAVEUV_ON + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + #endif + + #if ROUNDWAVEUV_ON + half _RoundWaveStrength, _RoundWaveSpeed; + #endif + + #if ZOOMUV_ON + half _ZoomUvAmount; + #endif + + #if FADE_ON + sampler2D _FadeTex, _FadeBurnTex; + half4 _FadeBurnColor, _FadeTex_ST, _FadeBurnTex_ST; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + #endif + + #if TEXTURESCROLL_ON + half _TextureScrollXSpeed, _TextureScrollYSpeed; + #endif + + #if GLOW_ON + sampler2D _GlowTex; + half4 _GlowColor; + half _Glow, _GlowGlobal; + #endif + + #if OUTBASE_ON + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + #endif + + #if OUTTEX_ON + sampler2D _OutlineTex; + half4 _OutlineTex_ST; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + #endif + + #if OUTDIST_ON + sampler2D _OutlineDistortTex; + half4 _OutlineDistortTex_ST; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + #endif + + #if DISTORT_ON + sampler2D _DistortTex; + half4 _DistortTex_ST; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + #endif + + #if WARP_ON + half _WarpStrength, _WarpSpeed, _WarpScale; + #endif + + #if WIND_ON + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + #endif + + #if GRADIENT_ON + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + #endif + + #if COLORSWAP_ON + sampler2D _ColorSwapTex; + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + #endif + + #if HSV_ON + half _HsvShift, _HsvSaturation, _HsvBright; + #endif + + #if HITEFFECT_ON + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + #endif + + #if PIXELATE_ON + half _PixelateSize; + #endif + + #if NEGATIVE_ON + half _NegativeAmount; + #endif + + #if COLORRAMP_ON + sampler2D _ColorRampTex, _ColorRampTexGradient; + half _ColorRampLuminosity, _ColorRampBlend; + #endif + + #if GREYSCALE_ON + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + #endif + + #if POSTERIZE_ON + half _PosterizeNumColors, _PosterizeGamma; + #endif + + #if BLUR_ON + half _BlurIntensity; + #endif + + #if MOTIONBLUR_ON + half _MotionBlurAngle, _MotionBlurDist; + #endif + + #if GHOST_ON + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + #endif + + #if ALPHAOUTLINE_ON + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + #endif + + #if INNEROUTLINE_ON + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + #endif + + #if HOLOGRAM_ON + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + #endif + + #if CHROMABERR_ON + half _ChromAberrAmount, _ChromAberrAlpha; + #endif + + #if GLITCH_ON + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + #endif + + #if FLICKER_ON + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + #endif + + #if SHADOW_ON + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + #endif + + #if SHINE_ON + sampler2D _ShineMask; + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + #endif + + #if ALPHACUTOFF_ON + half _AlphaCutoffValue; + #endif + + #if ALPHAROUND_ON + half _AlphaRoundThreshold; + #endif + + #if CHANGECOLOR_ON + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + #endif + #if CHANGECOLOR2_ON + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + #endif + #if CHANGECOLOR3_ON + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + #endif + + #if CONTRAST_ON + half _Contrast, _Brightness; + #endif + + #if OVERLAY_ON + sampler2D _OverlayTex; + half4 _OverlayTex_ST, _OverlayColor; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + #endif + + UNITY_INSTANCING_BUFFER_START(Props) + UNITY_DEFINE_INSTANCED_PROP(float, _RandomSeed) + UNITY_INSTANCING_BUFFER_END(Props) + + v2f vert(appdata v) + { + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.color = v.color; + + #if UNITY_UI_CLIP_RECT + half2 pixelSize = o.vertex.w; + pixelSize /= half2(1, 1) * abs(mul((half2x2)UNITY_MATRIX_P, _ScreenParams.xy)); + half4 clampedRect = clamp(_ClipRect, -2e10, 2e10); + half2 maskUV = (v.vertex.xy - clampedRect.xy) / (clampedRect.zw - clampedRect.xy); + o.mask = half4(v.vertex.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_UIMaskSoftnessX, _UIMaskSoftnessY) + abs(pixelSize.xy))); + #endif + + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + #if POLARUV_ON + o.uv = v.uv - center; + #endif + + #if ROTATEUV_ON + half2 uvC = v.uv; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + o.uv = mul(rot, uvC); + o.uv += center; + #endif + + #if OUTTEX_ON + o.uvOutTex = TRANSFORM_TEX(v.uv, _OutlineTex); + #endif + + #if OUTDIST_ON + o.uvOutDistTex = TRANSFORM_TEX(v.uv, _OutlineDistortTex); + #endif + + #if DISTORT_ON + o.uvDistTex = TRANSFORM_TEX(v.uv, _DistortTex); + #endif + + return o; + } + + half3 GetPixel(in int offsetX, in int offsetY, half2 uv, sampler2D tex) + { + return tex2D(tex, (uv + half2(offsetX * _MainTex_TexelSize.x, offsetY * _MainTex_TexelSize.y))).rgb; + } + + half4 frag(v2f i) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + half randomSeed = UNITY_ACCESS_INSTANCED_PROP(Props, _RandomSeed); + + float2 uvRect = i.uv; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((i.uv.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ST.x, center.y * _MainTex_ST.y); + + #if CLIPPING_ON + half2 tiledUv = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + #if TEXTURESCROLL_ON && ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((((globalUnscaledTime * 20) + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs((((globalUnscaledTime * 20) + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + + #if OFFSETUV_ON + #if ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + i.uv += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + #if POLARUV_ON + i.uv = half2(atan2(i.uv.y, i.uv.x) / (2.0f * 3.141592653589f), length(i.uv)); + i.uv *= _MainTex_ST.xy; + #endif + + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = i.uv - half2(_TwistUvPosX * _MainTex_ST.x, _TwistUvPosY * _MainTex_ST.y); + _TwistUvRadius *= (_MainTex_ST.x + _MainTex_ST.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ST.x, _TwistUvPosY * _MainTex_ST.y); + i.uv = tempUv; + #endif + + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = i.uv - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + i.uv = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + + #if PINCH_ON + half2 dP = i.uv - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + i.uv = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + #if ZOOMUV_ON + i.uv -= centerTiled; + i.uv = i.uv * _ZoomUvAmount; + i.uv += centerTiled; + #endif + + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((globalUnscaledTime + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + i.uv = lerp(i.uv, i.uv + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + #if SHAKEUV_ON + half xShake = sin((globalUnscaledTime + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((globalUnscaledTime + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + i.uv += half2(xShake * 0.012, yShake * 0.01); + #endif + + #if RECTSIZE_ON + i.uv = i.uv.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + #if DISTORT_ON + #if ATLAS_ON + i.uvDistTex.x = i.uvDistTex.x * (1 / (_MaxXUV - _MinXUV)); + i.uvDistTex.y = i.uvDistTex.y * (1 / (_MaxYUV - _MinYUV)); + #endif + i.uvDistTex.x += ((globalUnscaledTime + randomSeed) * _DistortTexXSpeed) % 1; + i.uvDistTex.y += ((globalUnscaledTime + randomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (tex2D(_DistortTex, i.uvDistTex).r - 0.5) * 0.2 * _DistortAmount; + i.uv.x += distortAmnt; + i.uv.y += distortAmnt; + #endif + + #if WARP_ON + half2 warpUv = half2(i.uv.x / _MainTex_ST.x, i.uv.y / _MainTex_ST.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = ((globalUnscaledTime * 20) + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = ((globalUnscaledTime * 20) + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + i.uv += warp; + #endif + + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ST.x, _WaveY * _MainTex_ST.y) - i.uv; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = (globalUnscaledTime * 20) + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + i.uv = i.uv + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ST.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ST.y) - uvRect.y) * (_MainTex_TexelSize.w / _MainTex_TexelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + i.uv += (sin((ripple + ((globalUnscaledTime * 20) + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + + #if WIND_ON + half windOffset = sin((globalUnscaledTime + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = i.uv - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + i.uv = i.uv + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + #if TEXTURESCROLL_ON && !ATLAS_ON + i.uv.x += (((globalUnscaledTime * 20) + randomSeed) * _TextureScrollXSpeed) % 1; + i.uv.y += (((globalUnscaledTime * 20) + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + + #if PIXELATE_ON + half aspectRatio = _MainTex_TexelSize.x / _MainTex_TexelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + i.uv = floor(i.uv * pixelSize) / pixelSize; + #endif + + half4 col = tex2D(_MainTex, i.uv); + half originalAlpha = col.a; + col *= i.color; + #if PREMULTIPLYALPHA_ON + col.rgb *= col.a; + #endif + + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2CustomTime(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, globalUnscaledTime, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2CustomTime(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, globalUnscaledTime, _GlitchSpeed), 3.0); + col = tex2D(_MainTex, i.uv + half2(lineNoise * 0.02 * rand2CustomTime(half2(2.0, 1), randomSeed, globalUnscaledTime, _GlitchSpeed), 0)) * i.color; + #endif + + #if CHROMABERR_ON + half4 r = tex2D(_MainTex, i.uv + half2(_ChromAberrAmount/10, 0)) * i.color; + half4 b = tex2D(_MainTex, i.uv + half2(-_ChromAberrAmount/10, 0)) * i.color; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * i.color; + #else + col = Blur(i.uv, _MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * i.color; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, _BlurIntensity, 1, 1) * i.color; + #else + col = Blur(i.uv, _MainTex, _BlurIntensity) * i.color; + #endif + #endif + #endif + + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += tex2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + half luminance = 0; + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + + #if INNEROUTLINE_ON + half3 innerT = abs(GetPixel(0, _InnerOutlineThickness, i.uv, _MainTex) - GetPixel(0, -_InnerOutlineThickness, i.uv, _MainTex)); + innerT += abs(GetPixel(_InnerOutlineThickness, 0, i.uv, _MainTex) - GetPixel(-_InnerOutlineThickness, 0, i.uv, _MainTex)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ST.x, uvRect.y / _MainTex_ST.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (_MainTex_TexelSize.w / _MainTex_TexelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = tex2D(_ColorSwapTex, i.uv); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, tex2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, tex2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + + #if OVERLAY_ON + half2 overlayUvs = uvRect; + overlayUvs.x += (((globalUnscaledTime * 20) + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += (((globalUnscaledTime * 20) + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = tex2D(_OverlayTex, TRANSFORM_TEX(overlayUvs, _OverlayTex)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //OUTLINE------------------------------------------------------------- + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * _MainTex_TexelSize.x, _OutlinePixelWidth * _MainTex_TexelSize.y); + #else + half2 destUv = half2(_OutlineWidth * _MainTex_TexelSize.x * 200, _OutlineWidth * _MainTex_TexelSize.y * 200); + #endif + + #if OUTDIST_ON + half2 uvOutDist = uvRect; + uvOutDist.x += ((globalUnscaledTime + randomSeed) * _OutlineDistortTexXSpeed) % 1; + uvOutDist.y += ((globalUnscaledTime + randomSeed) * _OutlineDistortTexYSpeed) % 1; + half outDistortAmnt = (tex2D(_OutlineDistortTex, TRANSFORM_TEX(uvOutDist, _OutlineDistortTex)).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = tex2D(_MainTex, i.uv + half2(destUv.x, 0)).a; + half spriteRight = tex2D(_MainTex, i.uv - half2(destUv.x, 0)).a; + half spriteBottom = tex2D(_MainTex, i.uv + half2(0, destUv.y)).a; + half spriteTop = tex2D(_MainTex, i.uv - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = tex2D(_MainTex, i.uv + half2(destUv.x, destUv.y)).a; + half spriteTopRight = tex2D(_MainTex, i.uv + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = tex2D(_MainTex, i.uv + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = tex2D(_MainTex, i.uv + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + i.uvOutTex.x += ((globalUnscaledTime + randomSeed) * _OutlineTexXSpeed) % 1; + i.uvOutTex.y += ((globalUnscaledTime + randomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + i.uvOutTex = half2((i.uvOutTex.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uvOutTex.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = tex2D(_OutlineTex, i.uvOutTex); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * i.color.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //----------------------------------------------------------------------------- + + #if FADE_ON + half2 tiledUvFade1= TRANSFORM_TEX(i.uv, _FadeTex); + half2 tiledUvFade2 = TRANSFORM_TEX(i.uv, _FadeBurnTex); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = tex2D(_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * tex2D(_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + + #if SHADOW_ON + half shadowA = tex2D(_MainTex, i.uv + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * i.color.a, col.a); + #endif + + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = tex2D(_GlowTex, i.uv); + #else + emission = col; + #endif + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, tex2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, tex2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = tex2D(_ShineMask, i.uv).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((globalUnscaledTime + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + ((globalUnscaledTime * 60) + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + + col.a *= _Alpha; + + #if UNITY_UI_CLIP_RECT + half2 clipMask = saturate((_ClipRect.zw - _ClipRect.xy - abs(i.mask.xy)) * i.mask.zw); + col.a *= clipMask.x * clipMask.y; + #endif + + #if UNITY_UI_ALPHACLIP + clip (col.a - 0.001); + #endif + + #if ALPHACUTOFF_ON + clip((1 - _AlphaCutoffValue) - (1 - col.a) - 0.01); + #endif + + #if ALPHAROUND_ON + col.a = step(_AlphaRoundThreshold, col.a); + #endif + + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + + col *= _Color; + + return col; + } + ENDCG + } + } + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderUiMaskMaterialInspector" + //Fallback "Sprites/Default" //Remove fallback so that any shader error is obvious to the user +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMaskScaledTime.shader.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMaskScaledTime.shader.meta new file mode 100644 index 0000000..c75fd2d --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMaskScaledTime.shader.meta @@ -0,0 +1,29 @@ +fileFormatVersion: 2 +guid: e89361f7792fee34fbaa655df899c819 +ShaderImporter: + externalObjects: {} + defaultTextures: + - _MainTex: {instanceID: 0} + - _GlowTex: {instanceID: 0} + - _FadeTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + - _FadeBurnTex: {fileID: 2800000, guid: 677cca399782dea41aedc1d292ecb67d, type: 3} + - _OutlineTex: {fileID: 2800000, guid: 74087f6d03f233e4a8a142fa01f9e5cf, type: 3} + - _OutlineDistortTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, + type: 3} + - _ColorSwapTex: {instanceID: 0} + - _ColorRampTex: {fileID: 2800000, guid: 279657edc397ece4b8029c727adf6ddc, type: 3} + - _DistortTex: {fileID: 2800000, guid: 7aad8c583ef292e48b06af0d1f2fab97, type: 3} + - _ShineMask: {instanceID: 0} + - _ColorRampTexGradient: {instanceID: 0} + - _OverlayTex: {fileID: 2800000, guid: 677cca399782dea41aedc1d292ecb67d, type: 3} + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1SpriteShaderUiMaskScaledTime.shader + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1Urp2dRenderer.shader b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1Urp2dRenderer.shader new file mode 100644 index 0000000..9744163 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1Urp2dRenderer.shader @@ -0,0 +1,466 @@ +Shader "AllIn1SpriteShader/AllIn1Urp2dRenderer" +{ + Properties + { + [NoScaleOffset]_MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset]_FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + [NoScaleOffset]_FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + [NoScaleOffset]_OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset]_OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset]_DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 0.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset]_OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + _MaskTex("Lighting Mask", 2D) = "white" {} //172 + _LitAmount("Lit Amount", Range(0,1)) = 1 //173 + _NormalMap("Normal Map", 2D) = "bump" {} //174 + _NormalStrength("Normal Strength", Range(0,10)) = 1 //175 + [Toggle()] _GlowAffectLight("Glow affects light", Float) = 1 //176 + + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //179 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //180 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //181 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //182 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //183 + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //184 + /**/ + + + _ZTestMode ("Z Test Mode", Float) = 4 + _CullingOption ("Culling Option", float) = 0 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 + _EditorDrawers("Editor Drawers", Int) = 14 + } + + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "[12.0,17.2]" + } + + Tags {"Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" "CanUseSpriteAtlas" = "True" "PreviewType" = "Plane" "RenderPipeline"="UniversalPipeline"} + Blend [_MySrcMode] [_MyDstMode] + Cull Off + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + Pass //Main Light Shapes pass + { + Name "Main Pass" + Tags { "LightMode" = "Universal2D" } + + HLSLPROGRAM + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + + #if UNITY_VERSION >= 202230 + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/Core2D.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl" + + #pragma multi_compile_instancing + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_0 __ + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_1 __ + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_2 __ + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_3 __ + + #if USE_SHAPE_LIGHT_TYPE_0 + SHAPE_LIGHT(0) + #endif + + #if USE_SHAPE_LIGHT_TYPE_1 + SHAPE_LIGHT(1) + #endif + + #if USE_SHAPE_LIGHT_TYPE_2 + SHAPE_LIGHT(2) + #endif + + #if USE_SHAPE_LIGHT_TYPE_3 + SHAPE_LIGHT(3) + #endif + + #pragma vertex CombinedShapeLightVertex + #pragma fragment CombinedShapeLightFragment + + + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl" + #include_with_pragmas "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl" + + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl" + + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_VertexPass.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_FragmentPass.hlsl" + + + + + ENDHLSL + } + + Pass //Normal Mapping + { + Name "Normal Pass" + Tags { "LightMode" = "NormalsRendering" } + + HLSLPROGRAM + #pragma vertex NormalsRenderingVertex + #pragma fragment NormalsRenderingFragment + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #if UNITY_VERSION >= 202230 + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/Core2D.hlsl" + #endif + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/NormalsRenderingShared.hlsl" + + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl" + #include_with_pragmas "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl" + + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingVertexPass.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingFragmentPass.hlsl" + + ENDHLSL + } + } + + + SubShader + { + PackageRequirements + { + "com.unity.render-pipelines.universal" : "17.3" + } + + Tags {"Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" "CanUseSpriteAtlas" = "True" "PreviewType" = "Plane" "RenderPipeline"="UniversalPipeline"} + Blend [_MySrcMode] [_MyDstMode] + Cull Off + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + Pass //Main Light Shapes pass + { + Name "Main Pass" + + Tags { "LightMode" = "Universal2D" } + + HLSLPROGRAM + #pragma vertex CombinedShapeLightVertex + #pragma fragment CombinedShapeLightFragment + + #pragma multi_compile_instancing + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_0 __ + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_1 __ + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_2 __ + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_3 __ + + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/Core2D.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl" + + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl" + #include_with_pragmas "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl" + + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_VertexPass.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_FragmentPass.hlsl" + + ENDHLSL + } + + Pass //Normal Mapping + { + Name "Normal Pass" + + Tags { "LightMode" = "NormalsRendering" } + + HLSLPROGRAM + #pragma vertex NormalsRenderingVertex + #pragma fragment NormalsRenderingFragment + + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/Core2D.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/NormalsRenderingShared.hlsl" + + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl" + #include_with_pragmas "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl" + + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingVertexPass.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingFragmentPass.hlsl" + + ENDHLSL + } + + Pass //Universal Forward + { + Name "Universal Forward" + + Tags { "LightMode" = "UniversalForward" "Queue"="Transparent" "RenderType"="Transparent"} + + HLSLPROGRAM + #pragma vertex CombinedShapeLightVertex + #pragma fragment CombinedShapeLightFragment + + #pragma multi_compile_instancing + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_0 __ + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_1 __ + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_2 __ + #pragma multi_compile USE_SHAPE_LIGHT_TYPE_3 __ + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/Core2D.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl" + + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl" + #include_with_pragmas "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl" + + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_VertexPass.hlsl" + #include "ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_FragmentPass.hlsl" + + ENDHLSL + } + } + + //FallBack "AllIn1SpriteShader/AllIn1SpriteShader" + CustomEditor "AllIn1SpriteShader.AllIn12DRendererMaterialInspector" +} \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1Urp2dRenderer.shader.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1Urp2dRenderer.shader.meta new file mode 100644 index 0000000..33c2fff --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1Urp2dRenderer.shader.meta @@ -0,0 +1,16 @@ +fileFormatVersion: 2 +guid: 202ffec9202f22e478034613d6beb49c +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/AllIn1Urp2dRenderer.shader + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders.meta new file mode 100644 index 0000000..153166a --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ab83761dc46d94e4e90385302b0cd179 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader.surfshader b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader.surfshader new file mode 100644 index 0000000..69e1624 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader.surfshader @@ -0,0 +1,1382 @@ +BEGIN_OPTIONS + Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" + ShaderName "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +END_OPTIONS + +BEGIN_PROPERTIES + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 +END_PROPERTIES + + +BEGIN_DEFINES + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb +END_DEFINES + +BEGIN_CBUFFER + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + +END_CBUFFER + +BEGIN_PASS("Forward") + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] +END_PASS + +BEGIN_PASS("GBuffer") + Cull [_CullingOption] +END_PASS + +BEGIN_CODE + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void ModifyVertex(inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void SurfaceFunction(inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + +END_CODE \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader.surfshader.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader.surfshader.meta new file mode 100644 index 0000000..a6d358a --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader.surfshader.meta @@ -0,0 +1,17 @@ +fileFormatVersion: 2 +guid: 906fe447de9ad3b4e8d21d6ba60deb8a +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: ed1b96e11e9064957833ce8c01da6f92, type: 3} +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader.surfshader + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2019.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2019.txt new file mode 100644 index 0000000..f28f30f --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2019.txt @@ -0,0 +1,16487 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: HDRP2019 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + + [HideInInspector] _StencilRef("Vector1 ", Int) = 0 + [HideInInspector] _StencilWriteMask("Vector1 ", Int) = 3 + [HideInInspector] _StencilRefDepth("Vector1 ", Int) = 0 + [HideInInspector] _StencilWriteMaskDepth("Vector1 ", Int) = 32 + [HideInInspector] _StencilRefMV("Vector1 ", Int) = 128 + [HideInInspector] _StencilWriteMaskMV("Vector1 ", Int) = 128 + [HideInInspector] _StencilRefDistortionVec("Vector1 ", Int) = 64 + [HideInInspector] _StencilWriteMaskDistortionVec("Vector1 ", Int) = 64 + [HideInInspector] _StencilWriteMaskGBuffer("Vector1 ", Int) = 3 + [HideInInspector] _StencilRefGBuffer("Vector1 ", Int) = 2 + [HideInInspector] _ZTestGBuffer("Vector1 ", Int) = 4 + [HideInInspector] [ToggleUI] _RequireSplitLighting("Boolean", Float) = 0 + [HideInInspector] [ToggleUI] _ReceivesSSR("Boolean", Float) = 1 + [HideInInspector] _SurfaceType("Vector1 ", Float) = 0 + [HideInInspector] [ToggleUI] _ZWrite("Boolean", Float) = 0 + [HideInInspector] _TransparentSortPriority("Vector1 ", Int) = 0 + [HideInInspector] _ZTestDepthEqualForOpaque("Vector1 ", Int) = 4 + [HideInInspector] [Enum(UnityEngine.Rendering.CompareFunction)] _ZTestTransparent("Vector1", Float) = 4 + [HideInInspector] [ToggleUI] _TransparentBackfaceEnable("Boolean", Float) = 0 + [HideInInspector] [ToggleUI] _AlphaCutoffEnable("Boolean", Float) = 0 + [HideInInspector] [ToggleUI] _UseShadowThreshold("Boolean", Float) = 0 + [HideInInspector] _BlendMode("Float", Float) = 0 + } + SubShader + { + Tags { "RenderPipeline"="HDRenderPipeline" "RenderPipeline" = "HDRenderPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + Pass + { + // based on HDLitPass.template + Name "Forward" + Tags { "LightMode" = "Forward" } + + + + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMask] + Ref [_StencilRef] + Comp Always + Pass Replace + } + + ColorMask [_ColorMaskTransparentVel] 1 + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + // #pragma multi_compile _ LOD_FADE_CROSSFADE + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADDITIVE _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_FORWARD + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + #pragma multi_compile _ DEBUG_DISPLAY + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ SHADOWS_SHADOWMASK + #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST + #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #define REQUIRE_DEPTH_TEXTURE + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + + void Frag(PackedVaryingsToPS packedInput, + #ifdef OUTPUT_SPLIT_LIGHTING + out float4 outColor : SV_Target0, // outSpecularLighting + out float4 outDiffuseLighting : SV_Target1, + OUTPUT_SSSBUFFER(outSSSBuffer) + #else + out float4 outColor : SV_Target0 + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + , out float4 outMotionVec : SV_Target1 + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + #endif // OUTPUT_SPLIT_LIGHTING + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + // Init outMotionVector here to solve compiler warning (potentially unitialized variable) + // It is init to the value of forceNoMotion (with 2.0) + outMotionVec = float4(2.0, 0.0, 0.0, 0.0); + #endif + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer. + input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy; + + uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + + PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); + + outColor = float4(0.0, 0.0, 0.0, 0.0); + + // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. + + #ifdef DEBUG_DISPLAY + // Init in debug display mode to quiet warning + #ifdef OUTPUT_SPLIT_LIGHTING + outDiffuseLighting = 0; + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #endif + + + + // Same code in ShaderPassForwardUnlit.shader + // Reminder: _DebugViewMaterialArray[i] + // i==0 -> the size used in the buffer + // i>0 -> the index used (0 value means nothing) + // The index stored in this buffer could either be + // - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported) + // - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty) + bool viewMaterial = false; + int bufferSize = int(_DebugViewMaterialArray[0]); + if (bufferSize != 0) + { + bool needLinearToSRGB = false; + float3 result = float3(1.0, 0.0, 1.0); + + // Loop through the whole buffer + // Works because GetSurfaceDataDebug will do nothing if the index is not a known one + for (int index = 1; index <= bufferSize; index++) + { + int indexMaterialProperty = int(_DebugViewMaterialArray[index]); + + // skip if not really in use + if (indexMaterialProperty != 0) + { + viewMaterial = true; + + GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB); + GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB); + GetBuiltinDataDebug(indexMaterialProperty, builtinData, result, needLinearToSRGB); + GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB); + GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB); + } + } + + // TEMP! + // For now, the final blit in the backbuffer performs an sRGB write + // So in the meantime we apply the inverse transform to linear data to compensate. + if (!needLinearToSRGB) + result = SRGBToLinear(max(0, result)); + + outColor = float4(result, 1.0); + } + + if (!viewMaterial) + { + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR) + { + float3 result = float3(0.0, 0.0, 0.0); + + GetPBRValidatorDebug(surfaceData, result); + + outColor = float4(result, 1.0f); + } + else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) + { + float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A); + outColor = result; + } + else + #endif + { + #ifdef _SURFACE_TYPE_TRANSPARENT + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; + #else + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; + #endif + + float3 diffuseLighting; + float3 specularLighting; + + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + { + LightLoopOutput lightLoopOutput; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput); + + // Alias + diffuseLighting = lightLoopOutput.diffuseLighting; + specularLighting = lightLoopOutput.specularLighting; + } + #else + { + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting); + } + #endif + + diffuseLighting *= GetCurrentExposureMultiplier(); + specularLighting *= GetCurrentExposureMultiplier(); + + #ifdef OUTPUT_SPLIT_LIGHTING + if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) + { + outColor = float4(specularLighting, 1.0); + outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); + } + else + { + outColor = float4(diffuseLighting + specularLighting, 1.0); + outDiffuseLighting = 0; + } + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #else + outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); + outColor = EvaluateAtmosphericScattering(posInput, V, outColor); + #endif + + ChainFinalColorForward(l, d, outColor); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + VaryingsPassToPS inputPass = UnpackVaryingsPassToPS(packedInput.vpass); + bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0); + // outMotionVec is already initialize at the value of forceNoMotion (see above) + if (!forceNoMotion) + { + float2 motionVec = CalculateMotionVector(inputPass.positionCS, inputPass.previousPositionCS); + EncodeMotionVector(motionVec * 0.5, outMotionVec); + outMotionVec.zw = 1.0; + } + #endif + } + + #ifdef DEBUG_DISPLAY + } + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "GBuffer" + Tags { "LightMode" = "GBuffer" } + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + ZTest [_ZTestGBuffer] + + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskGBuffer] + Ref [_StencilRefGBuffer] + Comp Always + Pass Replace + } + Cull [_CullingOption] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + #define SHADERPASS SHADERPASS_GBUFFER + #pragma multi_compile _ DEBUG_DISPLAY + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ SHADOWS_SHADOWMASK + #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile _ LIGHT_LAYERS + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + void Frag( PackedVaryingsToPS packedInput, + OUTPUT_GBUFFER(outGBuffer) + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + ZClip [_ZClip] + ZWrite On + ZTest LEqual + + ColorMask 0 + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_SHADOWS + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + + + void Frag( PackedVaryingsToPS packedInput + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "META" + Tags { "LightMode" = "META" } + + Cull Off + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + #define _PASSMETA 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + + float4 Frag(PackedVaryingsToPS packedInput + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + + ) : SV_Target + { + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // no debug apply during light transport pass + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); + + // This shader is call two times. Once for getting emissiveColor, the other time to get diffuseColor + // We use unity_MetaFragmentControl to make the distinction. + float4 res = float4(0.0, 0.0, 0.0, 1.0); + + if (unity_MetaFragmentControl.x) + { + // Apply diffuseColor Boost from LightmapSettings. + // put abs here to silent a warning, no cost, no impact as color is assume to be positive. + res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); + } + + if (unity_MetaFragmentControl.y) + { + // emissive use HDR format + res.rgb = lightTransportData.emissiveColor; + } + + return res; + } + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + ColorMask 0 + + + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENESELECTIONPASS + #pragma editor_sync_compilation + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSSCENESELECT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + + + void Frag( PackedVaryingsToPS packedInput + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + Pass + { + // based on HDLitPass.template + Name "DepthOnly" + Tags { "LightMode" = "DepthOnly" } + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + + ZWrite On + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskDepth] + Ref [_StencilRefDepth] + Comp Always + Pass Replace + } + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + // #pragma multi_compile _ LOD_FADE_CROSSFADE + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSDEPTH 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + + void Frag( PackedVaryingsToPS packedInput + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // to prevent stripping + surfaceData.normalWS *= saturate(l.Albedo.r + 9999); + + + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + + + + + } + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2019.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2019.txt.meta new file mode 100644 index 0000000..f3a1660 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2019.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 399eb10a7a397d147aedd61cb363c5b0 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2019.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2020.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2020.txt new file mode 100644 index 0000000..eef2c77 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2020.txt @@ -0,0 +1,25121 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: HDRP2020 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + + [HideInInspector]_RenderQueueType("Float", Float) = 1 + [HideInInspector][ToggleUI]_AddPrecomputedVelocity("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_DepthOffsetEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentWritingMotionVec("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaCutoffEnable("Boolean", Float) = 0 + [HideInInspector]_TransparentSortPriority("_TransparentSortPriority", Float) = 0 + [HideInInspector][ToggleUI]_UseShadowThreshold("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPrepassEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPostpassEnable("Boolean", Float) = 0 + [HideInInspector]_SurfaceType("Float", Float) = 0 + [HideInInspector]_BlendMode("Float", Float) = 0 + [HideInInspector]_SrcBlend("Float", Float) = 1 + [HideInInspector]_DstBlend("Float", Float) = 0 + [HideInInspector]_AlphaSrcBlend("Float", Float) = 1 + [HideInInspector]_AlphaDstBlend("Float", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMask("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMaskInspectorValue("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ZWrite("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_TransparentZWrite("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableFogOnTransparent("Boolean", Float) = 1 + [HideInInspector]_ZTestDepthEqualForOpaque("Float", Int) = 4 + [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestTransparent("Float", Float) = 4 + [HideInInspector][ToggleUI]_TransparentBackfaceEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_RequireSplitLighting("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ReceivesSSR("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_ReceivesSSRTransparent("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableBlendModePreserveSpecularLighting("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_SupportDecals("Boolean", Float) = 1 + [HideInInspector]_StencilRef("Float", Int) = 0 + [HideInInspector]_StencilWriteMask("Float", Int) = 6 + [HideInInspector]_StencilRefDepth("Float", Int) = 8 + [HideInInspector]_StencilWriteMaskDepth("Float", Int) = 8 + [HideInInspector]_StencilRefMV("Float", Int) = 40 + [HideInInspector]_StencilWriteMaskMV("Float", Int) = 40 + [HideInInspector]_StencilRefDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskGBuffer("Float", Int) = 14 + [HideInInspector]_StencilRefGBuffer("Float", Int) = 10 + [HideInInspector]_ZTestGBuffer("Float", Int) = 4 + [HideInInspector][ToggleUI]_RayTracing("Boolean", Float) = 0 + [HideInInspector][Enum(None, 0, Box, 1, Sphere, 2, Thin, 3)]_RefractionModel("Float", Float) = 0 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline" = "HDRenderPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + Pass + { + // based on HDLitPass.template + Name "Forward" + Tags { "LightMode" = "Forward" } + + + + Stencil + { + WriteMask [_StencilWriteMask] + Ref [_StencilRef] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + ColorMask [_ColorMaskTransparentVel] 1 + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ SHADOWS_SHADOWMASK + #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON + #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_FORWARD + #define SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING + #define HAS_LIGHTLOOP + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #ifdef UNITY_VIRTUAL_TEXTURING + #define VT_BUFFER_TARGET SV_Target1 + #define EXTRA_BUFFER_TARGET SV_Target2 + #else + #define EXTRA_BUFFER_TARGET SV_Target1 + #endif + + + + + void Frag(VertexToPixel v2p, + #ifdef OUTPUT_SPLIT_LIGHTING + out float4 outColor : SV_Target0, // outSpecularLighting + #ifdef UNITY_VIRTUAL_TEXTURING + out float4 outVTFeedback : VT_BUFFER_TARGET, + #endif + out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET, + OUTPUT_SSSBUFFER(outSSSBuffer) + #else + out float4 outColor : SV_Target0 + #ifdef UNITY_VIRTUAL_TEXTURING + ,out float4 outVTFeedback : VT_BUFFER_TARGET + #endif + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + , out float4 outMotionVec : EXTRA_BUFFER_TARGET + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + #endif // OUTPUT_SPLIT_LIGHTING + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + // Init outMotionVector here to solve compiler warning (potentially unitialized variable) + // It is init to the value of forceNoMotion (with 2.0) + outMotionVec = float4(2.0, 0.0, 0.0, 0.0); + #endif + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer. + input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy; + + uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + + PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); + + outColor = float4(0.0, 0.0, 0.0, 0.0); + + // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. + + #ifdef DEBUG_DISPLAY + // Init in debug display mode to quiet warning + #ifdef OUTPUT_SPLIT_LIGHTING + outDiffuseLighting = 0; + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #endif + + + + // Same code in ShaderPassForwardUnlit.shader + // Reminder: _DebugViewMaterialArray[i] + // i==0 -> the size used in the buffer + // i>0 -> the index used (0 value means nothing) + // The index stored in this buffer could either be + // - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported) + // - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty) + bool viewMaterial = false; + int bufferSize = _DebugViewMaterialArray[0].x; + if (bufferSize != 0) + { + bool needLinearToSRGB = false; + float3 result = float3(1.0, 0.0, 1.0); + + // Loop through the whole buffer + // Works because GetSurfaceDataDebug will do nothing if the index is not a known one + for (int index = 1; index <= bufferSize; index++) + { + int indexMaterialProperty = _DebugViewMaterialArray[index].x; + + // skip if not really in use + if (indexMaterialProperty != 0) + { + viewMaterial = true; + + GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB); + GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB); + GetBuiltinDataDebug(indexMaterialProperty, builtinData, posInput, result, needLinearToSRGB); + GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB); + GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB); + } + } + + // TEMP! + // For now, the final blit in the backbuffer performs an sRGB write + // So in the meantime we apply the inverse transform to linear data to compensate. + if (!needLinearToSRGB) + result = SRGBToLinear(max(0, result)); + + outColor = float4(result, 1.0); + } + + if (!viewMaterial) + { + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR) + { + float3 result = float3(0.0, 0.0, 0.0); + + GetPBRValidatorDebug(surfaceData, result); + + outColor = float4(result, 1.0f); + } + else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) + { + float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A); + outColor = result; + } + else + #endif + { + #ifdef _SURFACE_TYPE_TRANSPARENT + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; + #else + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; + #endif + + LightLoopOutput lightLoopOutput; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput); + + float3 diffuseLighting = lightLoopOutput.diffuseLighting; + float3 specularLighting = lightLoopOutput.specularLighting; + + diffuseLighting *= GetCurrentExposureMultiplier(); + specularLighting *= GetCurrentExposureMultiplier(); + + #ifdef OUTPUT_SPLIT_LIGHTING + if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) + { + outColor = float4(specularLighting, 1.0); + outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); + } + else + { + outColor = float4(diffuseLighting + specularLighting, 1.0); + outDiffuseLighting = 0; + } + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #else + outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); + outColor = EvaluateAtmosphericScattering(posInput, V, outColor); + #endif + + ChainFinalColorForward(l, d, outColor); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0); + // outMotionVec is already initialize at the value of forceNoMotion (see above) + if (!forceNoMotion) + { + float2 motionVec = CalculateMotionVector(v2p.motionVectorCS, v2p.previousPositionCS); + EncodeMotionVector(motionVec * 0.5, outMotionVec); + outMotionVec.zw = 1.0; + } + #endif + } + + #ifdef DEBUG_DISPLAY + } + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + outVTFeedback = builtinData.vtPackedFeedback; + #endif + } + + ENDHLSL + } + Pass + { + // based on HDLitPass.template + Name "GBuffer" + Tags { "LightMode" = "GBuffer" } + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZTest [_ZTestGBuffer] + Stencil + { + WriteMask [_StencilWriteMaskGBuffer] + Ref [_StencilRefGBuffer] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + Cull [_CullingOption] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + + #pragma multi_compile _ LIGHT_LAYERS + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ SHADOWS_SHADOWMASK + #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_GBUFFER + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + void Frag( VertexToPixel v2f, + OUTPUT_GBUFFER(outGBuffer) + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZWrite On + ColorMask 0 + ZClip [_ZClip] + + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_SHADOWS + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + #endif + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + + + } + + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "DepthOnly" + Tags { "LightMode" = "DepthOnly" } + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + + ZWrite On + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskDepth] + Ref [_StencilRefDepth] + Comp Always + Pass Replace + } + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSDEPTH 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2p + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + // to prevent stripping + surfaceData.normalWS *= saturate(l.Albedo.r + 9999); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + } + + + + ENDHLSL + } + + + + Pass + { + // based on HDLitPass.template + Name "META" + Tags { "LightMode" = "META" } + + Cull Off + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + #define _PASSMETA 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + float4 Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // no debug apply during light transport pass + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); + + // This shader is call two times. Once for getting emissiveColor, the other time to get diffuseColor + // We use unity_MetaFragmentControl to make the distinction. + float4 res = float4(0.0, 0.0, 0.0, 1.0); + + if (unity_MetaFragmentControl.x) + { + // Apply diffuseColor Boost from LightmapSettings. + // put abs here to silent a warning, no cost, no impact as color is assume to be positive. + res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); + } + + if (unity_MetaFragmentControl.y) + { + // emissive use HDR format + res.rgb = lightTransportData.emissiveColor; + } + + return res; + } + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + Cull Off + ColorMask 0 + + + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define SCENESELECTIONPASS + #define _PASSSCENESELECT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + void Frag( VertexToPixel IN + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + FragInputs input = BuildFragInputs(IN); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(IN, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + Pass + { + Name "ScenePickingPass" + Tags + { + "LightMode" = "Picking" + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENEPICKINGPASS + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + + } + + ENDHLSL + } + + Pass + { + Name "MotionVectors" + Tags + { + "LightMode" = "MotionVectors" + } + + // Render State + Cull Back + ZWrite On + Stencil + { + WriteMask [_StencilWriteMaskMV] + Ref [_StencilRefMV] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + + #pragma multi_compile _ WRITE_MSAA_DEPTH + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ WRITE_NORMAL_BUFFER + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ WRITE_DECAL_BUFFER + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_MOTION_VECTORS + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define VARYINGS_NEED_PASS + #define _PASSMOTIONVECTOR 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#if defined(WRITE_DECAL_BUFFER) && defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target3 +#elif defined(WRITE_DECAL_BUFFER) || defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target2 +#else +#define SV_TARGET_NORMAL SV_Target1 +#endif + +// Caution: Motion vector pass is different from Depth prepass, it render normal buffer last instead of decal buffer last +// and thus, we force a write of 0 if _DISABLE_DECALS so we always write in the decal buffer. +// This is required as we can't make distinction between deferred (write normal buffer) and forward (write normal buffer) +// in the context of the motion vector pass. The cost is acceptable as it is only do object with motion vector (usualy skin object) +// that most of the time use Forward Material (so are already writing motion vector data). +// So note that here unlike for depth prepass we don't check && !defined(_DISABLE_DECALS) +void Frag( VertexToPixel v2f + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + , out float4 outMotionVector : SV_Target1 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target2 + #endif + #else + // When no MSAA, the motion vector is always the first buffer + , out float4 outMotionVector : SV_Target0 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target1 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_TARGET_NORMAL + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + + FragInputs input = BuildFragInputs(v2f); + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + #ifdef _DEPTHOFFSET_ON + v2f.motionVectorCS.w += builtinData.depthOffset; + v2f.previousPositionCS.w += builtinData.depthOffset; + #endif + + // TODO: How to allow overriden motion vector from GetSurfaceAndBuiltinData ? + float2 motionVector = CalculateMotionVector(v2f.motionVectorCS, v2f.previousPositionCS); + + // Convert from Clip space (-1..1) to NDC 0..1 space. + // Note it doesn't mean we don't have negative value, we store negative or positive offset in NDC space. + // Note: ((positionCS * 0.5 + 0.5) - (v2f.previousPositionCS * 0.5 + 0.5)) = (motionVector * 0.5) + EncodeMotionVector(motionVector * 0.5, outMotionVector); + + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + // Setting the motionVector to a value more than 2 set as a flag for "force no motion". This is valid because, given that the velocities are in NDC, + // a value of >1 can never happen naturally, unless explicitely set. + if (forceNoMotion) + outMotionVector = float4(2.0, 0.0, 0.0, 0.0); + + // Depth and Alpha to coverage + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif + #endif + + // Normal Buffer Processing + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) + DecalPrepassData decalPrepassData; + // Force a write in decal buffer even if decal is disab. This is a neutral value which have no impact for later pass + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + #endif + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + + Pass + { + Name "FullScreenDebug" + Tags + { + "LightMode" = "FullScreenDebug" + } + + // Render State + Cull Back + ZTest LEqual + ZWrite Off + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_FULL_SCREEN_DEBUG + #define _PASSFULLSCREENDEBUG 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#define DEBUG_DISPLAY +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/FullScreenDebug.hlsl" + + #if !defined(_DEPTHOFFSET_ON) + [earlydepthstencil] // quad overshading debug mode writes to UAV + #endif + void Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz); + + #ifdef PLATFORM_SUPPORTS_PRIMITIVE_ID_IN_PIXEL_SHADER + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_QUAD_OVERDRAW) + { + IncrementQuadOverdrawCounter(posInput.positionSS.xy, input.primitiveID); + } + #endif + } + + ENDHLSL + } + + + + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2020.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2020.txt.meta new file mode 100644 index 0000000..fa82ac1 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2020.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: a647821724afdce49a1ba80aff36898d +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2020.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2021.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2021.txt new file mode 100644 index 0000000..a5c5ed7 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2021.txt @@ -0,0 +1,24976 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: HDRP2021 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + + [HideInInspector]_RenderQueueType("Float", Float) = 1 + [HideInInspector][ToggleUI]_AddPrecomputedVelocity("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_DepthOffsetEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentWritingMotionVec("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaCutoffEnable("Boolean", Float) = 0 + [HideInInspector]_TransparentSortPriority("_TransparentSortPriority", Float) = 0 + [HideInInspector][ToggleUI]_UseShadowThreshold("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPrepassEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPostpassEnable("Boolean", Float) = 0 + [HideInInspector]_SurfaceType("Float", Float) = 0 + [HideInInspector]_BlendMode("Float", Float) = 0 + [HideInInspector]_SrcBlend("Float", Float) = 1 + [HideInInspector]_DstBlend("Float", Float) = 0 + [HideInInspector]_AlphaSrcBlend("Float", Float) = 1 + [HideInInspector]_AlphaDstBlend("Float", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMask("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMaskInspectorValue("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ZWrite("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_TransparentZWrite("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableFogOnTransparent("Boolean", Float) = 1 + [HideInInspector]_ZTestDepthEqualForOpaque("Float", Int) = 4 + [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestTransparent("Float", Float) = 4 + [HideInInspector][ToggleUI]_TransparentBackfaceEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_RequireSplitLighting("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ReceivesSSR("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_ReceivesSSRTransparent("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableBlendModePreserveSpecularLighting("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_SupportDecals("Boolean", Float) = 1 + [HideInInspector]_StencilRef("Float", Int) = 0 + [HideInInspector]_StencilWriteMask("Float", Int) = 6 + [HideInInspector]_StencilRefDepth("Float", Int) = 8 + [HideInInspector]_StencilWriteMaskDepth("Float", Int) = 8 + [HideInInspector]_StencilRefMV("Float", Int) = 40 + [HideInInspector]_StencilWriteMaskMV("Float", Int) = 40 + [HideInInspector]_StencilRefDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskGBuffer("Float", Int) = 14 + [HideInInspector]_StencilRefGBuffer("Float", Int) = 10 + [HideInInspector]_ZTestGBuffer("Float", Int) = 4 + [HideInInspector][ToggleUI]_RayTracing("Boolean", Float) = 0 + [HideInInspector][Enum(None, 0, Box, 1, Sphere, 2, Thin, 3)]_RefractionModel("Float", Float) = 0 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline" = "HDRenderPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + Pass + { + // based on HDLitPass.template + Name "Forward" + Tags { "LightMode" = "Forward" } + + + + Stencil + { + WriteMask [_StencilWriteMask] + Ref [_StencilRef] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + ColorMask [_ColorMaskTransparentVel] 1 + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile_raytracing PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_raytracing _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH + #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON + #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST + + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_FORWARD + #define SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING + #define HAS_LIGHTLOOP + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #ifdef UNITY_VIRTUAL_TEXTURING + #define VT_BUFFER_TARGET SV_Target1 + #define EXTRA_BUFFER_TARGET SV_Target2 + #else + #define EXTRA_BUFFER_TARGET SV_Target1 + #endif + + + + + void Frag(VertexToPixel v2p, + #ifdef OUTPUT_SPLIT_LIGHTING + out float4 outColor : SV_Target0, // outSpecularLighting + #ifdef UNITY_VIRTUAL_TEXTURING + out float4 outVTFeedback : VT_BUFFER_TARGET, + #endif + out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET, + OUTPUT_SSSBUFFER(outSSSBuffer) + #else + out float4 outColor : SV_Target0 + #ifdef UNITY_VIRTUAL_TEXTURING + ,out float4 outVTFeedback : VT_BUFFER_TARGET + #endif + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + , out float4 outMotionVec : EXTRA_BUFFER_TARGET + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + #endif // OUTPUT_SPLIT_LIGHTING + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + // Init outMotionVector here to solve compiler warning (potentially unitialized variable) + // It is init to the value of forceNoMotion (with 2.0) + outMotionVec = float4(2.0, 0.0, 0.0, 0.0); + #endif + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer. + input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy; + + uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + + PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); + + outColor = float4(0.0, 0.0, 0.0, 0.0); + + // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. + + #ifdef DEBUG_DISPLAY + // Init in debug display mode to quiet warning + #ifdef OUTPUT_SPLIT_LIGHTING + outDiffuseLighting = 0; + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #endif + + + + // Same code in ShaderPassForwardUnlit.shader + // Reminder: _DebugViewMaterialArray[i] + // i==0 -> the size used in the buffer + // i>0 -> the index used (0 value means nothing) + // The index stored in this buffer could either be + // - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported) + // - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty) + bool viewMaterial = false; + int bufferSize = _DebugViewMaterialArray[0].x; + if (bufferSize != 0) + { + bool needLinearToSRGB = false; + float3 result = float3(1.0, 0.0, 1.0); + + // Loop through the whole buffer + // Works because GetSurfaceDataDebug will do nothing if the index is not a known one + for (int index = 1; index <= bufferSize; index++) + { + int indexMaterialProperty = _DebugViewMaterialArray[index].x; + + // skip if not really in use + if (indexMaterialProperty != 0) + { + viewMaterial = true; + + GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB); + GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB); + GetBuiltinDataDebug(indexMaterialProperty, builtinData, posInput, result, needLinearToSRGB); + GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB); + GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB); + } + } + + // TEMP! + // For now, the final blit in the backbuffer performs an sRGB write + // So in the meantime we apply the inverse transform to linear data to compensate. + if (!needLinearToSRGB) + result = SRGBToLinear(max(0, result)); + + outColor = float4(result, 1.0); + } + + if (!viewMaterial) + { + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR) + { + float3 result = float3(0.0, 0.0, 0.0); + + GetPBRValidatorDebug(surfaceData, result); + + outColor = float4(result, 1.0f); + } + else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) + { + float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A); + outColor = result; + } + else + #endif + { + #ifdef _SURFACE_TYPE_TRANSPARENT + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; + #else + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; + #endif + + LightLoopOutput lightLoopOutput; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput); + + float3 diffuseLighting = lightLoopOutput.diffuseLighting; + float3 specularLighting = lightLoopOutput.specularLighting; + + diffuseLighting *= GetCurrentExposureMultiplier(); + specularLighting *= GetCurrentExposureMultiplier(); + + #ifdef OUTPUT_SPLIT_LIGHTING + if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) + { + outColor = float4(specularLighting, 1.0); + outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); + } + else + { + outColor = float4(diffuseLighting + specularLighting, 1.0); + outDiffuseLighting = 0; + } + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #else + outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); + outColor = EvaluateAtmosphericScattering(posInput, V, outColor); + #endif + + ChainFinalColorForward(l, d, outColor); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0); + // outMotionVec is already initialize at the value of forceNoMotion (see above) + if (!forceNoMotion) + { + float2 motionVec = CalculateMotionVector(v2p.motionVectorCS, v2p.previousPositionCS); + EncodeMotionVector(motionVec * 0.5, outMotionVec); + outMotionVec.zw = 1.0; + } + #endif + } + + #ifdef DEBUG_DISPLAY + } + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + outVTFeedback = builtinData.vtPackedFeedback; + #endif + } + + ENDHLSL + } + Pass + { + // based on HDLitPass.template + Name "GBuffer" + Tags { "LightMode" = "GBuffer" } + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZTest [_ZTestGBuffer] + Stencil + { + WriteMask [_StencilWriteMaskGBuffer] + Ref [_StencilRefGBuffer] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + Cull [_CullingOption] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + + #pragma multi_compile _ LIGHT_LAYERS + #pragma multi_compile_raytracing _ LIGHT_LAYERS + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile_raytracing PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_raytracing _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_GBUFFER + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + void Frag( VertexToPixel v2f, + OUTPUT_GBUFFER(outGBuffer) + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZWrite On + ColorMask 0 + ZClip [_ZClip] + + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_SHADOWS + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + #endif + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + + + } + + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "DepthOnly" + Tags { "LightMode" = "DepthOnly" } + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + + ZWrite On + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskDepth] + Ref [_StencilRefDepth] + Comp Always + Pass Replace + } + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSDEPTH 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2p + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // to prevent stripping + surfaceData.normalWS *= saturate(l.Albedo.r + 9999); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + } + + + + ENDHLSL + } + + + + Pass + { + // based on HDLitPass.template + Name "META" + Tags { "LightMode" = "META" } + + Cull Off + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + #define _PASSMETA 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + float4 Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // no debug apply during light transport pass + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); + + // This shader is call two times. Once for getting emissiveColor, the other time to get diffuseColor + // We use unity_MetaFragmentControl to make the distinction. + float4 res = float4(0.0, 0.0, 0.0, 1.0); + + if (unity_MetaFragmentControl.x) + { + // Apply diffuseColor Boost from LightmapSettings. + // put abs here to silent a warning, no cost, no impact as color is assume to be positive. + res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); + } + + if (unity_MetaFragmentControl.y) + { + // emissive use HDR format + res.rgb = lightTransportData.emissiveColor; + } + + return res; + } + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + Cull Off + ColorMask 0 + + + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define SCENESELECTIONPASS + #define _PASSSCENESELECT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + void Frag( VertexToPixel IN + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + FragInputs input = BuildFragInputs(IN); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(IN, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + Pass + { + Name "ScenePickingPass" + Tags + { + "LightMode" = "Picking" + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENEPICKINGPASS + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + + } + + ENDHLSL + } + + Pass + { + Name "MotionVectors" + Tags + { + "LightMode" = "MotionVectors" + } + + // Render State + Cull Back + ZWrite On + Stencil + { + WriteMask [_StencilWriteMaskMV] + Ref [_StencilRefMV] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + + #pragma multi_compile _ WRITE_MSAA_DEPTH + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ WRITE_NORMAL_BUFFER + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ WRITE_DECAL_BUFFER + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_MOTION_VECTORS + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define VARYINGS_NEED_PASS + #define _PASSMOTIONVECTOR 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#if defined(WRITE_DECAL_BUFFER) && defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target3 +#elif defined(WRITE_DECAL_BUFFER) || defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target2 +#else +#define SV_TARGET_NORMAL SV_Target1 +#endif + +// Caution: Motion vector pass is different from Depth prepass, it render normal buffer last instead of decal buffer last +// and thus, we force a write of 0 if _DISABLE_DECALS so we always write in the decal buffer. +// This is required as we can't make distinction between deferred (write normal buffer) and forward (write normal buffer) +// in the context of the motion vector pass. The cost is acceptable as it is only do object with motion vector (usualy skin object) +// that most of the time use Forward Material (so are already writing motion vector data). +// So note that here unlike for depth prepass we don't check && !defined(_DISABLE_DECALS) +void Frag( VertexToPixel v2f + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + , out float4 outMotionVector : SV_Target1 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target2 + #endif + #else + // When no MSAA, the motion vector is always the first buffer + , out float4 outMotionVector : SV_Target0 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target1 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_TARGET_NORMAL + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + + FragInputs input = BuildFragInputs(v2f); + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + #ifdef _DEPTHOFFSET_ON + v2f.motionVectorCS.w += builtinData.depthOffset; + v2f.previousPositionCS.w += builtinData.depthOffset; + #endif + + // TODO: How to allow overriden motion vector from GetSurfaceAndBuiltinData ? + float2 motionVector = CalculateMotionVector(v2f.motionVectorCS, v2f.previousPositionCS); + + // Convert from Clip space (-1..1) to NDC 0..1 space. + // Note it doesn't mean we don't have negative value, we store negative or positive offset in NDC space. + // Note: ((positionCS * 0.5 + 0.5) - (v2f.previousPositionCS * 0.5 + 0.5)) = (motionVector * 0.5) + EncodeMotionVector(motionVector * 0.5, outMotionVector); + + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + // Setting the motionVector to a value more than 2 set as a flag for "force no motion". This is valid because, given that the velocities are in NDC, + // a value of >1 can never happen naturally, unless explicitely set. + if (forceNoMotion) + outMotionVector = float4(2.0, 0.0, 0.0, 0.0); + + // Depth and Alpha to coverage + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif + #endif + + // Normal Buffer Processing + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) + DecalPrepassData decalPrepassData; + // Force a write in decal buffer even if decal is disab. This is a neutral value which have no impact for later pass + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + #endif + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + outDecalBuffer.w = (GetMeshRenderingLightLayer() & 0x000000FF) / 255.0; + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + + Pass + { + Name "FullScreenDebug" + Tags + { + "LightMode" = "FullScreenDebug" + } + + // Render State + Cull Back + ZTest LEqual + ZWrite Off + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_FULL_SCREEN_DEBUG + #define _PASSFULLSCREENDEBUG 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#define DEBUG_DISPLAY +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/FullScreenDebug.hlsl" + + #if !defined(_DEPTHOFFSET_ON) + [earlydepthstencil] // quad overshading debug mode writes to UAV + #endif + void Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz); + + #ifdef PLATFORM_SUPPORTS_PRIMITIVE_ID_IN_PIXEL_SHADER + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_QUAD_OVERDRAW) + { + IncrementQuadOverdrawCounter(posInput.positionSS.xy, input.primitiveID); + } + #endif + } + + ENDHLSL + } + + + + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2021.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2021.txt.meta new file mode 100644 index 0000000..036f1cf --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2021.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: a5e970f81e60df04c8f073f570232b06 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2021.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2022.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2022.txt new file mode 100644 index 0000000..1c448bb --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2022.txt @@ -0,0 +1,25805 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: HDRP2022 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + + [HideInInspector]_RenderQueueType("Float", Float) = 1 + [HideInInspector][ToggleUI]_AddPrecomputedVelocity("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_DepthOffsetEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentWritingMotionVec("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaCutoffEnable("Boolean", Float) = 0 + [HideInInspector]_TransparentSortPriority("_TransparentSortPriority", Float) = 0 + [HideInInspector][ToggleUI]_UseShadowThreshold("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPrepassEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPostpassEnable("Boolean", Float) = 0 + [HideInInspector]_SurfaceType("Float", Float) = 0 + [HideInInspector]_BlendMode("Float", Float) = 0 + [HideInInspector]_SrcBlend("Float", Float) = 1 + [HideInInspector]_DstBlend("Float", Float) = 0 + [HideInInspector]_AlphaSrcBlend("Float", Float) = 1 + [HideInInspector]_AlphaDstBlend("Float", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMask("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMaskInspectorValue("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ZWrite("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_TransparentZWrite("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableFogOnTransparent("Boolean", Float) = 1 + [HideInInspector]_ZTestDepthEqualForOpaque("Float", Int) = 4 + [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestTransparent("Float", Float) = 4 + [HideInInspector][ToggleUI]_TransparentBackfaceEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_RequireSplitLighting("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ReceivesSSR("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_ReceivesSSRTransparent("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableBlendModePreserveSpecularLighting("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_SupportDecals("Boolean", Float) = 1 + [HideInInspector]_StencilRef("Float", Int) = 0 + [HideInInspector]_StencilWriteMask("Float", Int) = 6 + [HideInInspector]_StencilRefDepth("Float", Int) = 8 + [HideInInspector]_StencilWriteMaskDepth("Float", Int) = 8 + [HideInInspector]_StencilRefMV("Float", Int) = 40 + [HideInInspector]_StencilWriteMaskMV("Float", Int) = 40 + [HideInInspector]_StencilRefDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskGBuffer("Float", Int) = 14 + [HideInInspector]_StencilRefGBuffer("Float", Int) = 10 + [HideInInspector]_ZTestGBuffer("Float", Int) = 4 + [HideInInspector][ToggleUI]_RayTracing("Boolean", Float) = 0 + [HideInInspector][Enum(None, 0, Box, 1, Sphere, 2, Thin, 3)]_RefractionModel("Float", Float) = 0 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline" = "HDRenderPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + Pass + { + // based on HDLitPass.template + Name "Forward" + Tags { "LightMode" = "Forward" } + + + + Stencil + { + WriteMask [_StencilWriteMask] + Ref [_StencilRef] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + ColorMask [_ColorMaskTransparentVel] 1 + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile_raytracing PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_raytracing _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON + #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST + #pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH + #pragma multi_compile _ LOD_FADE_CROSSFADE + + + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_FORWARD + #define SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING + #define HAS_LIGHTLOOP + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #ifdef UNITY_VIRTUAL_TEXTURING + #define VT_BUFFER_TARGET SV_Target1 + #define EXTRA_BUFFER_TARGET SV_Target2 + #else + #define EXTRA_BUFFER_TARGET SV_Target1 + #endif + + + + + void Frag(VertexToPixel v2p, + #ifdef OUTPUT_SPLIT_LIGHTING + out float4 outColor : SV_Target0, // outSpecularLighting + #ifdef UNITY_VIRTUAL_TEXTURING + out float4 outVTFeedback : VT_BUFFER_TARGET, + #endif + out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET, + OUTPUT_SSSBUFFER(outSSSBuffer) + #else + out float4 outColor : SV_Target0 + #ifdef UNITY_VIRTUAL_TEXTURING + ,out float4 outVTFeedback : VT_BUFFER_TARGET + #endif + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + , out float4 outMotionVec : EXTRA_BUFFER_TARGET + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + #endif // OUTPUT_SPLIT_LIGHTING + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + // Init outMotionVector here to solve compiler warning (potentially unitialized variable) + // It is init to the value of forceNoMotion (with 2.0) + outMotionVec = float4(2.0, 0.0, 0.0, 0.0); + #endif + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer. + input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy; + + uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + + PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); + + outColor = float4(0.0, 0.0, 0.0, 0.0); + + // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. + + #ifdef DEBUG_DISPLAY + // Init in debug display mode to quiet warning + #ifdef OUTPUT_SPLIT_LIGHTING + outDiffuseLighting = 0; + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #endif + + + + // Same code in ShaderPassForwardUnlit.shader + // Reminder: _DebugViewMaterialArray[i] + // i==0 -> the size used in the buffer + // i>0 -> the index used (0 value means nothing) + // The index stored in this buffer could either be + // - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported) + // - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty) + bool viewMaterial = false; + int bufferSize = _DebugViewMaterialArray[0].x; + if (bufferSize != 0) + { + bool needLinearToSRGB = false; + float3 result = float3(1.0, 0.0, 1.0); + + // Loop through the whole buffer + // Works because GetSurfaceDataDebug will do nothing if the index is not a known one + for (int index = 1; index <= bufferSize; index++) + { + int indexMaterialProperty = _DebugViewMaterialArray[index].x; + + // skip if not really in use + if (indexMaterialProperty != 0) + { + viewMaterial = true; + + GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB); + GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB); + GetBuiltinDataDebug(indexMaterialProperty, builtinData, posInput, result, needLinearToSRGB); + GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB); + GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB); + } + } + + // TEMP! + // For now, the final blit in the backbuffer performs an sRGB write + // So in the meantime we apply the inverse transform to linear data to compensate. + if (!needLinearToSRGB) + result = SRGBToLinear(max(0, result)); + + outColor = float4(result, 1.0); + } + + if (!viewMaterial) + { + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR) + { + float3 result = float3(0.0, 0.0, 0.0); + + GetPBRValidatorDebug(surfaceData, result); + + outColor = float4(result, 1.0f); + } + else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) + { + float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A); + outColor = result; + } + else + #endif + { + #ifdef _SURFACE_TYPE_TRANSPARENT + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; + #else + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; + #endif + + LightLoopOutput lightLoopOutput; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput); + + float3 diffuseLighting = lightLoopOutput.diffuseLighting; + float3 specularLighting = lightLoopOutput.specularLighting; + + diffuseLighting *= GetCurrentExposureMultiplier(); + specularLighting *= GetCurrentExposureMultiplier(); + + #ifdef OUTPUT_SPLIT_LIGHTING + if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) + { + outColor = float4(specularLighting, 1.0); + outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); + } + else + { + outColor = float4(diffuseLighting + specularLighting, 1.0); + outDiffuseLighting = 0; + } + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #else + outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); + outColor = EvaluateAtmosphericScattering(posInput, V, outColor); + #endif + + ChainFinalColorForward(l, d, outColor); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0); + // outMotionVec is already initialize at the value of forceNoMotion (see above) + if (!forceNoMotion) + { + float2 motionVec = CalculateMotionVector(v2p.motionVectorCS, v2p.previousPositionCS); + EncodeMotionVector(motionVec * 0.5, outMotionVec); + outMotionVec.zw = 1.0; + } + #endif + } + + #ifdef DEBUG_DISPLAY + } + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + outVTFeedback = builtinData.vtPackedFeedback; + #endif + } + + ENDHLSL + } + Pass + { + // based on HDLitPass.template + Name "GBuffer" + Tags { "LightMode" = "GBuffer" } + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZTest [_ZTestGBuffer] + ColorMask [_LightLayersMaskBuffer4] 4 + ColorMask [_LightLayersMaskBuffer5] 5 + Stencil + { + WriteMask [_StencilWriteMaskGBuffer] + Ref [_StencilRefGBuffer] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + ColorMask [_LightLayersMaskBuffer4] 4 + ColorMask [_LightLayersMaskBuffer5] 5 + + Cull [_CullingOption] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma target 4.5 + + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + #pragma multi_compile _ LIGHT_LAYERS + //#pragma multi_compile_raytracing _ LIGHT_LAYERS + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_GBUFFER + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + void Frag( VertexToPixel v2f, + OUTPUT_GBUFFER(outGBuffer) + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZWrite On + ColorMask 0 + ZClip [_ZClip] + + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_SHADOWS + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + #endif + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + + + } + + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "DepthOnly" + Tags { "LightMode" = "DepthOnly" } + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + + ZWrite On + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskDepth] + Ref [_StencilRefDepth] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + AlphaToMask [_AlphaCutoffEnable] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH + #define _PASSDEPTH 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2p + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : DEPTH_OFFSET_SEMANTIC + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // to prevent stripping + surfaceData.normalWS *= saturate(l.Albedo.r + 9999); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = unity_SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + } + + + + ENDHLSL + } + + + + Pass + { + // based on HDLitPass.template + Name "META" + Tags { "LightMode" = "META" } + + Cull Off + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + #define _PASSMETA 1 + #pragma multi_compile _ LOD_FADE_CROSSFADE + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + float4 Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // no debug apply during light transport pass + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); + + // This shader is call two times. Once for getting emissiveColor, the other time to get diffuseColor + // We use unity_MetaFragmentControl to make the distinction. + float4 res = float4(0.0, 0.0, 0.0, 1.0); + + if (unity_MetaFragmentControl.x) + { + // Apply diffuseColor Boost from LightmapSettings. + // put abs here to silent a warning, no cost, no impact as color is assume to be positive. + res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); + } + + if (unity_MetaFragmentControl.y) + { + // emissive use HDR format + res.rgb = lightTransportData.emissiveColor; + } + + return res; + } + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + Cull Off + ColorMask 0 + + + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define SCENESELECTIONPASS + #define _PASSSCENESELECT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + void Frag( VertexToPixel IN + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + FragInputs input = BuildFragInputs(IN); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(IN, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + Pass + { + Name "ScenePickingPass" + Tags + { + "LightMode" = "Picking" + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENEPICKINGPASS + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + + } + + ENDHLSL + } + + Pass + { + Name "MotionVectors" + Tags + { + "LightMode" = "MotionVectors" + } + + // Render State + Cull Back + ZWrite On + Stencil + { + WriteMask [_StencilWriteMaskMV] + Ref [_StencilRefMV] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma multi_compile _ WRITE_MSAA_DEPTH + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ WRITE_NORMAL_BUFFER + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ WRITE_DECAL_BUFFER + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_MOTION_VECTORS + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define VARYINGS_NEED_PASS + #define _PASSMOTIONVECTOR 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#if defined(WRITE_DECAL_BUFFER) && defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target3 +#elif defined(WRITE_DECAL_BUFFER) || defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target2 +#else +#define SV_TARGET_NORMAL SV_Target1 +#endif + +// Caution: Motion vector pass is different from Depth prepass, it render normal buffer last instead of decal buffer last +// and thus, we force a write of 0 if _DISABLE_DECALS so we always write in the decal buffer. +// This is required as we can't make distinction between deferred (write normal buffer) and forward (write normal buffer) +// in the context of the motion vector pass. The cost is acceptable as it is only do object with motion vector (usualy skin object) +// that most of the time use Forward Material (so are already writing motion vector data). +// So note that here unlike for depth prepass we don't check && !defined(_DISABLE_DECALS) +void Frag( VertexToPixel v2f + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + , out float4 outMotionVector : SV_Target1 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target2 + #endif + #else + // When no MSAA, the motion vector is always the first buffer + , out float4 outMotionVector : SV_Target0 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target1 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_TARGET_NORMAL + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + + FragInputs input = BuildFragInputs(v2f); + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + #ifdef _DEPTHOFFSET_ON + v2f.motionVectorCS.w += builtinData.depthOffset; + v2f.previousPositionCS.w += builtinData.depthOffset; + #endif + + // TODO: How to allow overriden motion vector from GetSurfaceAndBuiltinData ? + float2 motionVector = CalculateMotionVector(v2f.motionVectorCS, v2f.previousPositionCS); + + // Convert from Clip space (-1..1) to NDC 0..1 space. + // Note it doesn't mean we don't have negative value, we store negative or positive offset in NDC space. + // Note: ((positionCS * 0.5 + 0.5) - (v2f.previousPositionCS * 0.5 + 0.5)) = (motionVector * 0.5) + EncodeMotionVector(motionVector * 0.5, outMotionVector); + + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + // Setting the motionVector to a value more than 2 set as a flag for "force no motion". This is valid because, given that the velocities are in NDC, + // a value of >1 can never happen naturally, unless explicitely set. + if (forceNoMotion) + outMotionVector = float4(2.0, 0.0, 0.0, 0.0); + + // Depth and Alpha to coverage + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif + #endif + + // Normal Buffer Processing + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) + DecalPrepassData decalPrepassData; + // Force a write in decal buffer even if decal is disab. This is a neutral value which have no impact for later pass + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + #endif + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + outDecalBuffer.w = (GetMeshRenderingLightLayer() & 0x000000FF) / 255.0; + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + + Pass + { + Name "FullScreenDebug" + Tags + { + "LightMode" = "FullScreenDebug" + } + + // Render State + Cull Back + ZTest LEqual + ZWrite Off + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ LOD_FADE_CROSSFADE + + + #define SHADERPASS SHADERPASS_FULL_SCREEN_DEBUG + #define _PASSFULLSCREENDEBUG 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#define DEBUG_DISPLAY +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/FullScreenDebug.hlsl" + + #if !defined(_DEPTHOFFSET_ON) + [earlydepthstencil] // quad overshading debug mode writes to UAV + #endif + void Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz); + + #ifdef PLATFORM_SUPPORTS_PRIMITIVE_ID_IN_PIXEL_SHADER + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_QUAD_OVERDRAW) + { + IncrementQuadOverdrawCounter(posInput.positionSS.xy, input.primitiveID); + } + #endif + } + + ENDHLSL + } + + + + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2022.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2022.txt.meta new file mode 100644 index 0000000..7996976 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2022.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 9e1b3d9455d4c4b41ae7fe2ce00204de +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2022.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2023.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2023.txt new file mode 100644 index 0000000..24de075 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2023.txt @@ -0,0 +1,25856 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: HDRP2023 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + + [HideInInspector]_RenderQueueType("Float", Float) = 1 + [HideInInspector][ToggleUI]_AddPrecomputedVelocity("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_DepthOffsetEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentWritingMotionVec("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaCutoffEnable("Boolean", Float) = 0 + [HideInInspector]_TransparentSortPriority("_TransparentSortPriority", Float) = 0 + [HideInInspector][ToggleUI]_UseShadowThreshold("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPrepassEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPostpassEnable("Boolean", Float) = 0 + [HideInInspector]_SurfaceType("Float", Float) = 0 + [HideInInspector]_BlendMode("Float", Float) = 0 + [HideInInspector]_SrcBlend("Float", Float) = 1 + [HideInInspector]_DstBlend("Float", Float) = 0 + [HideInInspector]_AlphaSrcBlend("Float", Float) = 1 + [HideInInspector]_AlphaDstBlend("Float", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMask("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMaskInspectorValue("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ZWrite("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_TransparentZWrite("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableFogOnTransparent("Boolean", Float) = 1 + [HideInInspector]_ZTestDepthEqualForOpaque("Float", Int) = 4 + [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestTransparent("Float", Float) = 4 + [HideInInspector][ToggleUI]_TransparentBackfaceEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_RequireSplitLighting("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ReceivesSSR("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_ReceivesSSRTransparent("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableBlendModePreserveSpecularLighting("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_SupportDecals("Boolean", Float) = 1 + [HideInInspector]_StencilRef("Float", Int) = 0 + [HideInInspector]_StencilWriteMask("Float", Int) = 6 + [HideInInspector]_StencilRefDepth("Float", Int) = 8 + [HideInInspector]_StencilWriteMaskDepth("Float", Int) = 8 + [HideInInspector]_StencilRefMV("Float", Int) = 40 + [HideInInspector]_StencilWriteMaskMV("Float", Int) = 40 + [HideInInspector]_StencilRefDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskGBuffer("Float", Int) = 14 + [HideInInspector]_StencilRefGBuffer("Float", Int) = 10 + [HideInInspector]_ZTestGBuffer("Float", Int) = 4 + [HideInInspector][ToggleUI]_RayTracing("Boolean", Float) = 0 + [HideInInspector][Enum(None, 0, Box, 1, Sphere, 2, Thin, 3)]_RefractionModel("Float", Float) = 0 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline" = "HDRenderPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + Pass + { + // based on HDLitPass.template + Name "Forward" + Tags { "LightMode" = "Forward" } + + + + Stencil + { + WriteMask [_StencilWriteMask] + Ref [_StencilRef] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + ColorMask [_ColorMaskTransparentVel] 1 + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON + #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST + #pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH + #pragma multi_compile _ LOD_FADE_CROSSFADE + #pragma multi_compile _ USE_LEGACY_LIGHTMAPS + + + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_FORWARD + #define SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING + #define HAS_LIGHTLOOP + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #ifdef UNITY_VIRTUAL_TEXTURING + #define VT_BUFFER_TARGET SV_Target1 + #define EXTRA_BUFFER_TARGET SV_Target2 + #else + #define EXTRA_BUFFER_TARGET SV_Target1 + #endif + + + + + void Frag(VertexToPixel v2p, + #ifdef OUTPUT_SPLIT_LIGHTING + out float4 outColor : SV_Target0, // outSpecularLighting + #ifdef UNITY_VIRTUAL_TEXTURING + out float4 outVTFeedback : VT_BUFFER_TARGET, + #endif + out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET, + OUTPUT_SSSBUFFER(outSSSBuffer) + #else + out float4 outColor : SV_Target0 + #ifdef UNITY_VIRTUAL_TEXTURING + ,out float4 outVTFeedback : VT_BUFFER_TARGET + #endif + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + , out float4 outMotionVec : EXTRA_BUFFER_TARGET + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + #endif // OUTPUT_SPLIT_LIGHTING + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + // Init outMotionVector here to solve compiler warning (potentially unitialized variable) + // It is init to the value of forceNoMotion (with 2.0) + outMotionVec = float4(2.0, 0.0, 0.0, 0.0); + #endif + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer. + input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy; + + uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + + PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); + + outColor = float4(0.0, 0.0, 0.0, 0.0); + + // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. + + #ifdef DEBUG_DISPLAY + // Init in debug display mode to quiet warning + #ifdef OUTPUT_SPLIT_LIGHTING + outDiffuseLighting = 0; + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #endif + + + + // Same code in ShaderPassForwardUnlit.shader + // Reminder: _DebugViewMaterialArray[i] + // i==0 -> the size used in the buffer + // i>0 -> the index used (0 value means nothing) + // The index stored in this buffer could either be + // - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported) + // - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty) + bool viewMaterial = false; + int bufferSize = _DebugViewMaterialArray[0].x; + if (bufferSize != 0) + { + bool needLinearToSRGB = false; + float3 result = float3(1.0, 0.0, 1.0); + + // Loop through the whole buffer + // Works because GetSurfaceDataDebug will do nothing if the index is not a known one + for (int index = 1; index <= bufferSize; index++) + { + int indexMaterialProperty = _DebugViewMaterialArray[index].x; + + // skip if not really in use + if (indexMaterialProperty != 0) + { + viewMaterial = true; + + GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB); + GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB); + GetBuiltinDataDebug(indexMaterialProperty, builtinData, posInput, result, needLinearToSRGB); + GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB); + GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB); + } + } + + // TEMP! + // For now, the final blit in the backbuffer performs an sRGB write + // So in the meantime we apply the inverse transform to linear data to compensate. + if (!needLinearToSRGB) + result = SRGBToLinear(max(0, result)); + + outColor = float4(result, 1.0); + } + + if (!viewMaterial) + { + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR) + { + float3 result = float3(0.0, 0.0, 0.0); + + GetPBRValidatorDebug(surfaceData, result); + + outColor = float4(result, 1.0f); + } + else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) + { + float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A); + outColor = result; + } + else + #endif + { + #ifdef _SURFACE_TYPE_TRANSPARENT + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; + #else + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; + #endif + + LightLoopOutput lightLoopOutput; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput); + + float3 diffuseLighting = lightLoopOutput.diffuseLighting; + float3 specularLighting = lightLoopOutput.specularLighting; + + diffuseLighting *= GetCurrentExposureMultiplier(); + specularLighting *= GetCurrentExposureMultiplier(); + + #ifdef OUTPUT_SPLIT_LIGHTING + if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) + { + outColor = float4(specularLighting, 1.0); + outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); + } + else + { + outColor = float4(diffuseLighting + specularLighting, 1.0); + outDiffuseLighting = 0; + } + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #else + outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); + outColor = EvaluateAtmosphericScattering(posInput, V, outColor); + #endif + + ChainFinalColorForward(l, d, outColor); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0); + // outMotionVec is already initialize at the value of forceNoMotion (see above) + if (!forceNoMotion) + { + float2 motionVec = CalculateMotionVector(v2p.motionVectorCS, v2p.previousPositionCS); + EncodeMotionVector(motionVec * 0.5, outMotionVec); + outMotionVec.zw = 1.0; + } + #endif + } + + #ifdef DEBUG_DISPLAY + } + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + outVTFeedback = builtinData.vtPackedFeedback; + #endif + } + + ENDHLSL + } + Pass + { + // based on HDLitPass.template + Name "GBuffer" + Tags { "LightMode" = "GBuffer" } + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZTest [_ZTestGBuffer] + Stencil + { + WriteMask [_StencilWriteMaskGBuffer] + Ref [_StencilRefGBuffer] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + Cull [_CullingOption] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma target 4.5 + + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ LOD_FADE_CROSSFADE + #pragma multi_compile_fragment _ RENDERING_LAYERS + //#pragma multi_compile_raytracing _ LIGHT_LAYERS + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + #pragma multi_compile _ USE_LEGACY_LIGHTMAPS + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_GBUFFER + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + void Frag( VertexToPixel v2f, + OUTPUT_GBUFFER(outGBuffer) + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZWrite On + ColorMask 0 + ZClip [_ZClip] + + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_SHADOWS + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + #endif + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER) + DecalPrepassData decalPrepassData; + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + #endif + decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + + + } + + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "DepthOnly" + Tags { "LightMode" = "DepthOnly" } + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + + ZWrite On + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskDepth] + Ref [_StencilRefDepth] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + AlphaToMask [_AlphaCutoffEnable] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH + #define _PASSDEPTH 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2p + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : DEPTH_OFFSET_SEMANTIC + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // to prevent stripping + surfaceData.normalWS *= saturate(l.Albedo.r + 9999); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = unity_SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER) + DecalPrepassData decalPrepassData; + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + #endif + decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + } + + + + ENDHLSL + } + + + + Pass + { + // based on HDLitPass.template + Name "META" + Tags { "LightMode" = "META" } + + Cull Off + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + #define _PASSMETA 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + float4 Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // no debug apply during light transport pass + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); + + // This shader is call two times. Once for getting emissiveColor, the other time to get diffuseColor + // We use unity_MetaFragmentControl to make the distinction. + float4 res = float4(0.0, 0.0, 0.0, 1.0); + + if (unity_MetaFragmentControl.x) + { + // Apply diffuseColor Boost from LightmapSettings. + // put abs here to silent a warning, no cost, no impact as color is assume to be positive. + res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); + } + + if (unity_MetaFragmentControl.y) + { + // emissive use HDR format + res.rgb = lightTransportData.emissiveColor; + } + + return res; + } + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + Cull Off + ColorMask 0 + + + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define SCENESELECTIONPASS + #define _PASSSCENESELECT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + void Frag( VertexToPixel IN + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + FragInputs input = BuildFragInputs(IN); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(IN, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + Pass + { + Name "ScenePickingPass" + Tags + { + "LightMode" = "Picking" + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENEPICKINGPASS + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER) + DecalPrepassData decalPrepassData; + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + #endif + decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + + } + + ENDHLSL + } + + Pass + { + Name "MotionVectors" + Tags + { + "LightMode" = "MotionVectors" + } + + // Render State + Cull Back + ZWrite On + Stencil + { + WriteMask [_StencilWriteMaskMV] + Ref [_StencilRefMV] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma multi_compile _ WRITE_MSAA_DEPTH + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ WRITE_NORMAL_BUFFER + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ WRITE_DECAL_BUFFER + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_MOTION_VECTORS + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define VARYINGS_NEED_PASS + #define _PASSMOTIONVECTOR 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#if defined(WRITE_DECAL_BUFFER) && defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target3 +#elif defined(WRITE_DECAL_BUFFER) || defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target2 +#else +#define SV_TARGET_NORMAL SV_Target1 +#endif + +// Caution: Motion vector pass is different from Depth prepass, it render normal buffer last instead of decal buffer last +// and thus, we force a write of 0 if _DISABLE_DECALS so we always write in the decal buffer. +// This is required as we can't make distinction between deferred (write normal buffer) and forward (write normal buffer) +// in the context of the motion vector pass. The cost is acceptable as it is only do object with motion vector (usualy skin object) +// that most of the time use Forward Material (so are already writing motion vector data). +// So note that here unlike for depth prepass we don't check && !defined(_DISABLE_DECALS) +void Frag( VertexToPixel v2f + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + , out float4 outMotionVector : SV_Target1 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target2 + #endif + #else + // When no MSAA, the motion vector is always the first buffer + , out float4 outMotionVector : SV_Target0 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target1 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_TARGET_NORMAL + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + + FragInputs input = BuildFragInputs(v2f); + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + #ifdef _DEPTHOFFSET_ON + v2f.motionVectorCS.w += builtinData.depthOffset; + v2f.previousPositionCS.w += builtinData.depthOffset; + #endif + + // TODO: How to allow overriden motion vector from GetSurfaceAndBuiltinData ? + float2 motionVector = CalculateMotionVector(v2f.motionVectorCS, v2f.previousPositionCS); + + // Convert from Clip space (-1..1) to NDC 0..1 space. + // Note it doesn't mean we don't have negative value, we store negative or positive offset in NDC space. + // Note: ((positionCS * 0.5 + 0.5) - (v2f.previousPositionCS * 0.5 + 0.5)) = (motionVector * 0.5) + EncodeMotionVector(motionVector * 0.5, outMotionVector); + + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + // Setting the motionVector to a value more than 2 set as a flag for "force no motion". This is valid because, given that the velocities are in NDC, + // a value of >1 can never happen naturally, unless explicitely set. + if (forceNoMotion) + outMotionVector = float4(2.0, 0.0, 0.0, 0.0); + + // Depth and Alpha to coverage + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif + #endif + + // Normal Buffer Processing + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) + DecalPrepassData decalPrepassData; + // Force a write in decal buffer even if decal is disab. This is a neutral value which have no impact for later pass + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask(); + #endif + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + outDecalBuffer.w = (GetMeshRenderingLayerMask() & 0x000000FF) / 255.0; + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + + Pass + { + Name "FullScreenDebug" + Tags + { + "LightMode" = "FullScreenDebug" + } + + // Render State + Cull Back + ZTest LEqual + ZWrite Off + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ LOD_FADE_CROSSFADE + + + #define SHADERPASS SHADERPASS_FULL_SCREEN_DEBUG + #define _PASSFULLSCREENDEBUG 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#define DEBUG_DISPLAY +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/FullScreenDebug.hlsl" + + #if !defined(_DEPTHOFFSET_ON) + [earlydepthstencil] // quad overshading debug mode writes to UAV + #endif + void Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz); + + #ifdef PLATFORM_SUPPORTS_PRIMITIVE_ID_IN_PIXEL_SHADER + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_QUAD_OVERDRAW) + { + IncrementQuadOverdrawCounter(posInput.positionSS.xy, input.primitiveID); + } + #endif + } + + ENDHLSL + } + + + + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2023.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2023.txt.meta new file mode 100644 index 0000000..d30a2c5 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2023.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: c397c4395866b3f43a53dfd559528372 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_HDRP2023.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_Standard.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_Standard.txt new file mode 100644 index 0000000..aa270ab --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_Standard.txt @@ -0,0 +1,17401 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: Standard +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + } + SubShader + { + Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } + + + + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + CGPROGRAM + // compile directives + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + #pragma multi_compile_instancing + #pragma multi_compile_fog + #pragma multi_compile_fwdbase + #include "HLSLSupport.cginc" + #define UNITY_INSTANCED_LOD_FADE + #define UNITY_INSTANCED_SH + #define UNITY_INSTANCED_LIGHTMAPSTS + + #include "UnityShaderVariables.cginc" + #include "UnityShaderUtilities.cginc" + // -------- variant for: + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + #include "AutoLight.cginc" + #define SHADER_PASS SHADERPASS_FORWARD + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _STANDARD 1 +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_GAMECORE) + + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r + #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_XBOXONE) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_PSSL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName + #define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + + +#elif defined(SHADER_API_D3D11) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined + // TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) + // This file assume SHADER_API_SWITCH is defined + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + + // OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 46) + #define OPENGL4_1_SM5 1 + #else + #define OPENGL4_1_SM5 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + + #if OPENGL4_1_SM5 + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #endif + + + #elif defined(SHADER_API_GLES3) + + // GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 40) + #define GLES3_1_AEP 1 + #else + #define GLES3_1_AEP 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #if GLES3_1_AEP + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + #else + #define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + #endif + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #if GLES3_1_AEP + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + #endif + + +#elif defined(SHADER_API_GLES) + + + #define uint int + + #define rcp(x) 1.0 / (x) + #define ddx_fine ddx + #define ddy_fine ddy + #define asfloat + #define asuint(x) asint(x) + #define f32tof16 + #define f16tof32 + + #define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + + // Texture abstraction + + #define TEXTURE2D(textureName) sampler2D textureName + #define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray + #define TEXTURECUBE(textureName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray + #define TEXTURE3D(textureName) sampler3D textureName + + #define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray + #define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray + #define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + + #define TEXTURE2D_HALF(textureName) sampler2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray + #define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray + #define TEXTURE3D_HALF(textureName) sampler3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + #define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + + #define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + + #define SAMPLER(samplerName) + #define SAMPLER_CMP(samplerName) + + #define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + + #if (SHADER_TARGET >= 30) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) + #else + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) + #endif + + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + + + // Not supported. Can't define as error because shader library is calling these functions. + #define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + + // Gather not supported. Fallback to regular texture sampling. + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + + + + +// default flow control attributes +#ifndef UNITY_BRANCH +# define UNITY_BRANCH +#endif +#ifndef UNITY_FLATTEN +# define UNITY_FLATTEN +#endif +#ifndef UNITY_UNROLL +# define UNITY_UNROLL +#endif +#ifndef UNITY_UNROLLX +# define UNITY_UNROLLX(_x) +#endif +#ifndef UNITY_LOOP +# define UNITY_LOOP +#endif + + + +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // data across stages, stripped like the above. + struct VertexToPixel + { + UNITY_POSITION(pos); + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + float4 lmap : TEXCOORD8; + #if UNITY_SHOULD_SAMPLE_SH + half3 sh : TEXCOORD9; // SH + #endif + #ifdef LIGHTMAP_ON + UNITY_LIGHTING_COORDS(10,11) + UNITY_FOG_COORDS(12) + #else + UNITY_FOG_COORDS(10) + UNITY_SHADOW_COORDS(11) + #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef UNITY_MATRIX_I_M + + #define UNITY_MATRIX_I_M unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)UNITY_MATRIX_V, norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + UNITY_SETUP_INSTANCE_ID(v); + VertexToPixel o; + UNITY_INITIALIZE_OUTPUT(VertexToPixel,o); + UNITY_TRANSFER_INSTANCE_ID(v,o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos); + // #endif + + o.worldPos = mul(GetObjectToWorldMatrix(), v.vertex).xyz; + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + #ifdef DYNAMICLIGHTMAP_ON + o.lmap.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + #ifdef LIGHTMAP_ON + o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + #endif + + // SH/ambient and vertex lights + #ifndef LIGHTMAP_ON + #if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL + o.sh = 0; + // Approximated illumination from non-important point lights + #ifdef VERTEXLIGHT_ON + o.sh += Shade4PointLights ( + unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0, + unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb, + unity_4LightAtten0, o.worldPos, o.worldNormal); + #endif + o.sh = ShadeSHPerVertex (o.worldNormal, o.sh); + #endif + #endif // !LIGHTMAP_ON + + UNITY_TRANSFER_LIGHTING(o,v.texcoord1.xy); // pass shadow and, possibly, light cookie coordinates to pixel shader + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_TRANSFER_FOG_COMBINED_WITH_TSPACE(o,o.pos); // pass fog coordinates to pixel shader + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_TRANSFER_FOG_COMBINED_WITH_WORLD_POS(o,o.pos); // pass fog coordinates to pixel shader + #else + UNITY_TRANSFER_FOG(o,o.pos); // pass fog coordinates to pixel shader + #endif + + return o; + } + + + + // fragment shader + fixed4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + // prepare and unpack data + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_EXTRACT_FOG_FROM_TSPACE(IN); + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN); + #else + UNITY_EXTRACT_FOG(IN); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + + #ifndef USING_DIRECTIONAL_LIGHT + fixed3 lightDir = normalize(UnityWorldSpaceLightDir(d.worldSpacePosition)); + #else + fixed3 lightDir = _WorldSpaceLightPos0.xyz; + #endif + float3 worldViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + + // compute lighting & shadowing factor + UNITY_LIGHT_ATTENUATION(atten, IN, d.worldSpacePosition) + + #if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0; + #else + SurfaceOutputStandardSpecular o; + #endif + o.Specular = l.Specular; + o.Occlusion = l.Occlusion; + o.Smoothness = l.Smoothness; + #elif _BDRFLAMBERT || _BDRF3 || _SIMPLELIT + #ifdef UNITY_COMPILER_HLSL + SurfaceOutput o = (SurfaceOutput)0; + #else + SurfaceOutput o; + #endif + + o.Specular = l.Specular; + o.Gloss = l.Smoothness; + _SpecColor.rgb = l.Specular; // fucking hell Unity, wtf.. + #else + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandard o = (SurfaceOutputStandard)0; + #else + SurfaceOutputStandard o; + #endif + o.Smoothness = l.Smoothness; + o.Metallic = l.Metallic; + o.Occlusion = l.Occlusion; + #endif + + o.Albedo = l.Albedo; + o.Emission = l.Emission; + o.Alpha = l.Alpha; + #if _WORLDSPACENORMAL + o.Normal = l.Normal; + #else + o.Normal = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + fixed4 c = 0; + // Setup lighting environment + UnityGI gi; + UNITY_INITIALIZE_OUTPUT(UnityGI, gi); + gi.indirect.diffuse = 0; + gi.indirect.specular = 0; + gi.light.color = _LightColor0.rgb; + gi.light.dir = lightDir; + // Call GI (lightmaps/SH/reflections) lighting function + UnityGIInput giInput; + UNITY_INITIALIZE_OUTPUT(UnityGIInput, giInput); + giInput.light = gi.light; + giInput.worldPos = d.worldSpacePosition; + giInput.worldViewDir = worldViewDir; + giInput.atten = atten; + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + giInput.lightmapUV = IN.lmap; + #else + giInput.lightmapUV = 0.0; + #endif + #if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL + giInput.ambient = IN.sh; + #else + giInput.ambient.rgb = 0.0; + #endif + giInput.probeHDR[0] = unity_SpecCube0_HDR; + giInput.probeHDR[1] = unity_SpecCube1_HDR; + #if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION) + giInput.boxMin[0] = unity_SpecCube0_BoxMin; // .w holds lerp value for blending + #endif + #ifdef UNITY_SPECCUBE_BOX_PROJECTION + giInput.boxMax[0] = unity_SpecCube0_BoxMax; + giInput.probePosition[0] = unity_SpecCube0_ProbePosition; + giInput.boxMax[1] = unity_SpecCube1_BoxMax; + giInput.boxMin[1] = unity_SpecCube1_BoxMin; + giInput.probePosition[1] = unity_SpecCube1_ProbePosition; + #endif + + + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, unity_OcclusionMaskSelector)); + gi.light.color *= mulColor; + giInput.light.color *= mulColor; + #endif + + #if _UNLIT + c.rgb = l.Albedo; + c.a = l.Alpha; + #elif _BDRF3 || _SIMPLELIT + LightingBlinnPhong_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + c += LightingBlinnPhong (o, d.worldSpaceViewDir, gi); + #elif _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC + LightingStandardSpecular_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + c += LightingStandardSpecular (o, d.worldSpaceViewDir, gi); + #else + LightingStandard_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + c += LightingStandard (o, d.worldSpaceViewDir, gi); + #endif + + c.rgb += o.Emission; + + ChainFinalColorForward(l, d, c); + + #if !DISABLEFOG + UNITY_APPLY_FOG(_unity_fogCoord, c); // apply fog + #endif + + + return c; + } + + ENDCG + + } + + + + // ---- deferred shading pass: + Pass + { + Name "DEFERRED" + Tags { "LightMode" = "Deferred" } + + Cull [_CullingOption] + + + CGPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + // compile directives + #pragma target 3.0 + #pragma multi_compile_instancing + #pragma exclude_renderers nomrt + #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2 + #pragma multi_compile_prepassfinal + #include "HLSLSupport.cginc" + #define UNITY_INSTANCED_LOD_FADE + #define UNITY_INSTANCED_SH + #define UNITY_INSTANCED_LIGHTMAPSTS + #include "UnityShaderVariables.cginc" + #include "UnityShaderUtilities.cginc" + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _STANDARD 1 +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_GAMECORE) + + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r + #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_XBOXONE) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_PSSL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName + #define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + + +#elif defined(SHADER_API_D3D11) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined + // TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) + // This file assume SHADER_API_SWITCH is defined + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + + // OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 46) + #define OPENGL4_1_SM5 1 + #else + #define OPENGL4_1_SM5 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + + #if OPENGL4_1_SM5 + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #endif + + + #elif defined(SHADER_API_GLES3) + + // GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 40) + #define GLES3_1_AEP 1 + #else + #define GLES3_1_AEP 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #if GLES3_1_AEP + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + #else + #define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + #endif + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #if GLES3_1_AEP + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + #endif + + +#elif defined(SHADER_API_GLES) + + + #define uint int + + #define rcp(x) 1.0 / (x) + #define ddx_fine ddx + #define ddy_fine ddy + #define asfloat + #define asuint(x) asint(x) + #define f32tof16 + #define f16tof32 + + #define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + + // Texture abstraction + + #define TEXTURE2D(textureName) sampler2D textureName + #define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray + #define TEXTURECUBE(textureName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray + #define TEXTURE3D(textureName) sampler3D textureName + + #define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray + #define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray + #define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + + #define TEXTURE2D_HALF(textureName) sampler2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray + #define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray + #define TEXTURE3D_HALF(textureName) sampler3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + #define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + + #define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + + #define SAMPLER(samplerName) + #define SAMPLER_CMP(samplerName) + + #define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + + #if (SHADER_TARGET >= 30) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) + #else + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) + #endif + + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + + + // Not supported. Can't define as error because shader library is calling these functions. + #define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + + // Gather not supported. Fallback to regular texture sampling. + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + + + + +// default flow control attributes +#ifndef UNITY_BRANCH +# define UNITY_BRANCH +#endif +#ifndef UNITY_FLATTEN +# define UNITY_FLATTEN +#endif +#ifndef UNITY_UNROLL +# define UNITY_UNROLL +#endif +#ifndef UNITY_UNROLLX +# define UNITY_UNROLLX(_x) +#endif +#ifndef UNITY_LOOP +# define UNITY_LOOP +#endif + + + +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + UNITY_POSITION(pos); // must be named pos because Unity does stupid macro stuff + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + #ifndef DIRLIGHTMAP_OFF + float3 viewDir : TEXCOORD8; + #endif + float4 lmap : TEXCOORD9; + #ifndef LIGHTMAP_ON + #if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL + half3 sh : TEXCOORD10; // SH + #endif + #else + #ifdef DIRLIGHTMAP_OFF + float4 lmapFadePos : TEXCOORD11; + #endif + #endif + + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD19; + // #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef UNITY_MATRIX_I_M + + #define UNITY_MATRIX_I_M unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)UNITY_MATRIX_V, norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + // vertex shader + VertexToPixel Vert (VertexData v) + { + UNITY_SETUP_INSTANCE_ID(v); + VertexToPixel o; + UNITY_INITIALIZE_OUTPUT(VertexToPixel,o); + UNITY_TRANSFER_INSTANCE_ID(v,o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos); + // #endif + + o.worldPos = mul(GetObjectToWorldMatrix(), v.vertex).xyz; + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + float3 viewDirForLight = UnityWorldSpaceViewDir(o.worldPos); + #ifndef DIRLIGHTMAP_OFF + float3 worldBinormal = cross(o.worldNormal, o.worldTangent.xyz); + o.viewDir.x = dot(viewDirForLight, o.worldTangent.xyz); + o.viewDir.y = dot(viewDirForLight, worldBinormal); + o.viewDir.z = dot(viewDirForLight, o.worldNormal); + #endif + #ifdef DYNAMICLIGHTMAP_ON + o.lmap.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #else + o.lmap.zw = 0; + #endif + #ifdef LIGHTMAP_ON + o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + #ifdef DIRLIGHTMAP_OFF + o.lmapFadePos.xyz = (mul(GetObjectToWorldMatrix(), v.vertex).xyz - unity_ShadowFadeCenterAndType.xyz) * unity_ShadowFadeCenterAndType.w; + o.lmapFadePos.w = (-UnityObjectToViewPos(v.vertex).z) * (1.0 - unity_ShadowFadeCenterAndType.w); + #endif + #else + o.lmap.xy = 0; + #if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL + o.sh = 0; + o.sh = ShadeSHPerVertex (o.worldNormal, o.sh); + #endif + #endif + + return o; + } + + + + #ifdef LIGHTMAP_ON + float4 unity_LightmapFade; + #endif + fixed4 unity_Ambient; + + + + // fragment shader + void Frag (VertexToPixel IN, + out half4 outGBuffer0 : SV_Target0, + out half4 outGBuffer1 : SV_Target1, + out half4 outGBuffer2 : SV_Target2, + out half4 outEmission : SV_Target3 + #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + , out half4 outShadowMask : SV_Target4 + #endif + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_INSTANCE_ID(IN); + // prepare and unpack data + + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_EXTRACT_FOG_FROM_TSPACE(IN); + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN); + #else + UNITY_EXTRACT_FOG(IN); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + + + + + #ifndef USING_DIRECTIONAL_LIGHT + fixed3 lightDir = normalize(UnityWorldSpaceLightDir(d.worldSpacePosition)); + #else + fixed3 lightDir = _WorldSpaceLightPos0.xyz; + #endif + float3 worldViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + + #if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0; + #else + SurfaceOutputStandardSpecular o; + #endif + o.Specular = l.Specular; + o.Occlusion = l.Occlusion; + o.Smoothness = l.Smoothness; + #elif _BDRFLAMBERT || _BDRF3 || _SIMPLELIT + #ifdef UNITY_COMPILER_HLSL + SurfaceOutput o = (SurfaceOutput)0; + #else + SurfaceOutput o; + #endif + + o.Specular = l.SpecularPower; + o.Gloss = l.Smoothness; + _SpecColor.rgb = l.Specular; // fucking hell Unity, wtf.. + #else + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandard o = (SurfaceOutputStandard)0; + #else + SurfaceOutputStandard o; + #endif + o.Smoothness = l.Smoothness; + o.Metallic = l.Metallic; + o.Occlusion = l.Occlusion; + #endif + + + + o.Albedo = l.Albedo; + o.Emission = l.Emission; + o.Alpha = l.Alpha; + + #if _WORLDSPACENORMAL + o.Normal = l.Normal; + #else + o.Normal = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + + half atten = 1; + + // Setup lighting environment + UnityGI gi; + UNITY_INITIALIZE_OUTPUT(UnityGI, gi); + gi.indirect.diffuse = 0; + gi.indirect.specular = 0; + gi.light.color = 0; + gi.light.dir = half3(0,1,0); + // Call GI (lightmaps/SH/reflections) lighting function + UnityGIInput giInput; + UNITY_INITIALIZE_OUTPUT(UnityGIInput, giInput); + giInput.light = gi.light; + giInput.worldPos = d.worldSpacePosition; + giInput.worldViewDir = worldViewDir; + giInput.atten = atten; + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + giInput.lightmapUV = IN.lmap; + #else + giInput.lightmapUV = 0.0; + #endif + #if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL + giInput.ambient = IN.sh; + #else + giInput.ambient.rgb = 0.0; + #endif + giInput.probeHDR[0] = unity_SpecCube0_HDR; + giInput.probeHDR[1] = unity_SpecCube1_HDR; + #if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION) + giInput.boxMin[0] = unity_SpecCube0_BoxMin; // .w holds lerp value for blending + #endif + #ifdef UNITY_SPECCUBE_BOX_PROJECTION + giInput.boxMax[0] = unity_SpecCube0_BoxMax; + giInput.probePosition[0] = unity_SpecCube0_ProbePosition; + giInput.boxMax[1] = unity_SpecCube1_BoxMax; + giInput.boxMin[1] = unity_SpecCube1_BoxMin; + giInput.probePosition[1] = unity_SpecCube1_ProbePosition; + #endif + + + + #if _BDRF3 || _SIMPLELIT + + LightingBlinnPhong_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + + outEmission = LightingBlinnPhong_Deferred(o, worldViewDir, gi, outGBuffer0, outGBuffer1, outGBuffer2); + #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + outShadowMask = UnityGetRawBakedOcclusions (IN.lmap.xy, d.worldSpacePosition); + #endif + #ifndef UNITY_HDR_ON + outEmission.rgb = exp2(-outEmission.rgb); + #endif + #elif _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC + LightingStandardSpecular_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + // call lighting function to output g-buffer + outEmission = LightingStandardSpecular_Deferred (o, worldViewDir, gi, outGBuffer0, outGBuffer1, outGBuffer2); + #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + outShadowMask = UnityGetRawBakedOcclusions (IN.lmap.xy, d.worldSpacePosition); + #endif + #ifndef UNITY_HDR_ON + outEmission.rgb = exp2(-outEmission.rgb); + #endif + #else + LightingStandard_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + // call lighting function to output g-buffer + outEmission = LightingStandard_Deferred (o, worldViewDir, gi, outGBuffer0, outGBuffer1, outGBuffer2); + #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + outShadowMask = UnityGetRawBakedOcclusions (IN.lmap.xy, d.worldSpacePosition); + #endif + #ifndef UNITY_HDR_ON + outEmission.rgb = exp2(-outEmission.rgb); + #endif + #endif + + #if defined(_OVERRIDE_SHADOWMASK) && defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + float4 mulColor = saturate(dot(l.ShadowMask, unity_OcclusionMaskSelector)); + outShadowMask = mulColor; + #endif + + #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + ChainFinalGBufferStandard(l, d, outGBuffer0, outGBuffer1, outGBuffer2, outEmission, outShadowMask); + #else + half4 outShadowMask = 0; + ChainFinalGBufferStandard(l, d, outGBuffer0, outGBuffer1, outGBuffer2, outEmission, outShadowMask); + #endif + + + } + + + + + ENDCG + + } + + + + + // ---- forward rendering additive lights pass: + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardAdd" } + ZWrite Off Blend One One + + + + CGPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + // compile directives + #pragma target 3.0 + #pragma multi_compile_instancing + #pragma multi_compile_fog + #pragma skip_variants INSTANCING_ON + #pragma multi_compile_fwdadd_fullshadows + #include "HLSLSupport.cginc" + #define UNITY_INSTANCED_LOD_FADE + #define UNITY_INSTANCED_SH + #define UNITY_INSTANCED_LIGHTMAPSTS + #include "UnityShaderVariables.cginc" + #include "UnityShaderUtilities.cginc" + + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + #include "AutoLight.cginc" + + + + #define _PASSFORWARD 1 + #define _PASSFORWARDADD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _STANDARD 1 +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_GAMECORE) + + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r + #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_XBOXONE) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_PSSL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName + #define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + + +#elif defined(SHADER_API_D3D11) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined + // TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) + // This file assume SHADER_API_SWITCH is defined + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + + // OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 46) + #define OPENGL4_1_SM5 1 + #else + #define OPENGL4_1_SM5 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + + #if OPENGL4_1_SM5 + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #endif + + + #elif defined(SHADER_API_GLES3) + + // GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 40) + #define GLES3_1_AEP 1 + #else + #define GLES3_1_AEP 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #if GLES3_1_AEP + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + #else + #define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + #endif + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #if GLES3_1_AEP + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + #endif + + +#elif defined(SHADER_API_GLES) + + + #define uint int + + #define rcp(x) 1.0 / (x) + #define ddx_fine ddx + #define ddy_fine ddy + #define asfloat + #define asuint(x) asint(x) + #define f32tof16 + #define f16tof32 + + #define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + + // Texture abstraction + + #define TEXTURE2D(textureName) sampler2D textureName + #define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray + #define TEXTURECUBE(textureName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray + #define TEXTURE3D(textureName) sampler3D textureName + + #define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray + #define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray + #define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + + #define TEXTURE2D_HALF(textureName) sampler2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray + #define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray + #define TEXTURE3D_HALF(textureName) sampler3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + #define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + + #define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + + #define SAMPLER(samplerName) + #define SAMPLER_CMP(samplerName) + + #define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + + #if (SHADER_TARGET >= 30) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) + #else + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) + #endif + + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + + + // Not supported. Can't define as error because shader library is calling these functions. + #define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + + // Gather not supported. Fallback to regular texture sampling. + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + + + + +// default flow control attributes +#ifndef UNITY_BRANCH +# define UNITY_BRANCH +#endif +#ifndef UNITY_FLATTEN +# define UNITY_FLATTEN +#endif +#ifndef UNITY_UNROLL +# define UNITY_UNROLL +#endif +#ifndef UNITY_UNROLLX +# define UNITY_UNROLLX(_x) +#endif +#ifndef UNITY_LOOP +# define UNITY_LOOP +#endif + + + +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // data across stages, stripped like the above. + struct VertexToPixel + { + UNITY_POSITION(pos); // must be named pos because Unity does stupid macro stuff + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + UNITY_LIGHTING_COORDS(8,9) + UNITY_FOG_COORDS(10) + + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD18; + // #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + + }; + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef UNITY_MATRIX_I_M + + #define UNITY_MATRIX_I_M unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)UNITY_MATRIX_V, norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + UNITY_SETUP_INSTANCE_ID(v); + VertexToPixel o; + UNITY_INITIALIZE_OUTPUT(VertexToPixel,o); + UNITY_TRANSFER_INSTANCE_ID(v,o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos); + // #endif + + o.worldPos = mul(GetObjectToWorldMatrix(), v.vertex).xyz; + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + UNITY_TRANSFER_LIGHTING(o, v.texcoord1.xy); // pass shadow and, possibly, light cookie coordinates to pixel shader + UNITY_TRANSFER_FOG(o,o.pos); // pass fog coordinates to pixel shader + + return o; + } + + + + // fragment shader + fixed4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + // prepare and unpack data + + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_EXTRACT_FOG_FROM_TSPACE(IN); + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN); + #else + UNITY_EXTRACT_FOG(IN); + #endif + + + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + + #ifndef USING_DIRECTIONAL_LIGHT + fixed3 lightDir = normalize(UnityWorldSpaceLightDir(d.worldSpacePosition)); + #else + fixed3 lightDir = _WorldSpaceLightPos0.xyz; + #endif + float3 worldViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + + #if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0; + #else + SurfaceOutputStandardSpecular o; + #endif + o.Specular = l.Specular; + o.Occlusion = l.Occlusion; + o.Smoothness = l.Smoothness; + #elif _BDRFLAMBERT || _BDRF3 || _SIMPLELIT + #ifdef UNITY_COMPILER_HLSL + SurfaceOutput o = (SurfaceOutput)0; + #else + SurfaceOutput o; + #endif + + o.Specular = l.SpecularPower; + o.Gloss = l.Smoothness; + _SpecColor.rgb = l.Specular; // fucking hell Unity, wtf.. + #else + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandard o = (SurfaceOutputStandard)0; + #else + SurfaceOutputStandard o; + #endif + o.Smoothness = l.Smoothness; + o.Metallic = l.Metallic; + o.Occlusion = l.Occlusion; + #endif + + + o.Albedo = l.Albedo; + o.Emission = l.Emission; + o.Alpha = l.Alpha; + + #if _WORLDSPACENORMAL + o.Normal = l.Normal; + #else + o.Normal = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + + + UNITY_LIGHT_ATTENUATION(atten, IN, d.worldSpacePosition) + half4 c = 0; + + // Setup lighting environment + UnityGI gi; + UNITY_INITIALIZE_OUTPUT(UnityGI, gi); + gi.indirect.diffuse = 0; + gi.indirect.specular = 0; + gi.light.color = _LightColor0.rgb; + gi.light.dir = lightDir; + gi.light.color *= atten; + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, unity_OcclusionMaskSelector)); + gi.light.color *= mulColor; + #endif + + #if _USESPECULAR + c += LightingStandardSpecular (o, worldViewDir, gi); + #elif _BDRF3 || _SIMPLELIT + c += LightingBlinnPhong (o, d.worldSpaceViewDir, gi); + #else + c += LightingStandard (o, worldViewDir, gi); + #endif + + + ChainFinalColorForward(l, d, c); + + #if !DISABLEFOG + UNITY_APPLY_FOG(_unity_fogCoord, c); // apply fog + #endif + #if !_ALPHABLEND_ON + UNITY_OPAQUE_ALPHA(c.a); + #endif + + return c; + } + + ENDCG + + } + + + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + ZWrite On ZTest LEqual + + + + CGPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + // compile directives + #pragma target 3.0 + #pragma multi_compile_instancing + #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2 + #pragma multi_compile_shadowcaster + #include "HLSLSupport.cginc" + #define UNITY_INSTANCED_LOD_FADE + #define UNITY_INSTANCED_SH + #define UNITY_INSTANCED_LIGHTMAPSTS + #include "UnityShaderVariables.cginc" + #include "UnityShaderUtilities.cginc" + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _STANDARD 1 +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_GAMECORE) + + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r + #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_XBOXONE) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_PSSL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName + #define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + + +#elif defined(SHADER_API_D3D11) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined + // TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) + // This file assume SHADER_API_SWITCH is defined + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + + // OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 46) + #define OPENGL4_1_SM5 1 + #else + #define OPENGL4_1_SM5 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + + #if OPENGL4_1_SM5 + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #endif + + + #elif defined(SHADER_API_GLES3) + + // GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 40) + #define GLES3_1_AEP 1 + #else + #define GLES3_1_AEP 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #if GLES3_1_AEP + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + #else + #define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + #endif + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #if GLES3_1_AEP + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + #endif + + +#elif defined(SHADER_API_GLES) + + + #define uint int + + #define rcp(x) 1.0 / (x) + #define ddx_fine ddx + #define ddy_fine ddy + #define asfloat + #define asuint(x) asint(x) + #define f32tof16 + #define f16tof32 + + #define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + + // Texture abstraction + + #define TEXTURE2D(textureName) sampler2D textureName + #define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray + #define TEXTURECUBE(textureName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray + #define TEXTURE3D(textureName) sampler3D textureName + + #define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray + #define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray + #define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + + #define TEXTURE2D_HALF(textureName) sampler2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray + #define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray + #define TEXTURE3D_HALF(textureName) sampler3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + #define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + + #define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + + #define SAMPLER(samplerName) + #define SAMPLER_CMP(samplerName) + + #define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + + #if (SHADER_TARGET >= 30) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) + #else + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) + #endif + + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + + + // Not supported. Can't define as error because shader library is calling these functions. + #define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + + // Gather not supported. Fallback to regular texture sampling. + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + + + + +// default flow control attributes +#ifndef UNITY_BRANCH +# define UNITY_BRANCH +#endif +#ifndef UNITY_FLATTEN +# define UNITY_FLATTEN +#endif +#ifndef UNITY_UNROLL +# define UNITY_UNROLL +#endif +#ifndef UNITY_UNROLLX +# define UNITY_UNROLLX(_x) +#endif +#ifndef UNITY_LOOP +# define UNITY_LOOP +#endif + + + +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + V2F_SHADOW_CASTER; // may declare TEXCOORD0 for the wonderfully named .vec + float3 worldPos : TEXCOORD1; + float3 worldNormal : TEXCOORD2; + float4 worldTangent : TEXCOORD3; + float4 texcoord0 : TEXCOORD4; + float4 texcoord1 : TEXCOORD5; + float4 texcoord2 : TEXCOORD6; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD7; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD8; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD16; + // #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef UNITY_MATRIX_I_M + + #define UNITY_MATRIX_I_M unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)UNITY_MATRIX_V, norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + // vertex shader + VertexToPixel Vert (VertexData v) + { + UNITY_SETUP_INSTANCE_ID(v); + VertexToPixel o; + UNITY_INITIALIZE_OUTPUT(VertexToPixel,o); + UNITY_TRANSFER_INSTANCE_ID(v,o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + + + o.worldPos = mul(GetObjectToWorldMatrix(), v.vertex).xyz; + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + // sets o.pos, so do screenpos after. + TRANSFER_SHADOW_CASTER_NORMALOFFSET(o) + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos); + // #endif + + return o; + } + + + + // fragment shader + fixed4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + // prepare and unpack data + + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_EXTRACT_FOG_FROM_TSPACE(IN); + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN); + #else + UNITY_EXTRACT_FOG(IN); + #endif + + #ifndef USING_DIRECTIONAL_LIGHT + fixed3 lightDir = normalize(UnityWorldSpaceLightDir(IN.worldPos)); + #else + fixed3 lightDir = _WorldSpaceLightPos0.xyz; + #endif + + + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + SHADOW_CASTER_FRAGMENT(IN) + } + + + ENDCG + + } + + + // ---- meta information extraction pass: + Pass + { + Name "Meta" + Tags { "LightMode" = "Meta" } + Cull Off + + + + CGPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + // compile directives + #pragma target 3.0 + #pragma multi_compile_instancing + #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2 + #pragma shader_feature EDITOR_VISUALIZATION + + #include "HLSLSupport.cginc" + #define UNITY_INSTANCED_LOD_FADE + #define UNITY_INSTANCED_SH + #define UNITY_INSTANCED_LIGHTMAPSTS + #include "UnityShaderVariables.cginc" + #include "UnityShaderUtilities.cginc" + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + #include "UnityMetaPass.cginc" + + #define _PASSMETA 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _STANDARD 1 +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_GAMECORE) + + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r + #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_XBOXONE) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_PSSL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName + #define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + + +#elif defined(SHADER_API_D3D11) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined + // TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) + // This file assume SHADER_API_SWITCH is defined + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + + // OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 46) + #define OPENGL4_1_SM5 1 + #else + #define OPENGL4_1_SM5 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + + #if OPENGL4_1_SM5 + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #endif + + + #elif defined(SHADER_API_GLES3) + + // GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 40) + #define GLES3_1_AEP 1 + #else + #define GLES3_1_AEP 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #if GLES3_1_AEP + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + #else + #define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + #endif + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #if GLES3_1_AEP + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + #endif + + +#elif defined(SHADER_API_GLES) + + + #define uint int + + #define rcp(x) 1.0 / (x) + #define ddx_fine ddx + #define ddy_fine ddy + #define asfloat + #define asuint(x) asint(x) + #define f32tof16 + #define f16tof32 + + #define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + + // Texture abstraction + + #define TEXTURE2D(textureName) sampler2D textureName + #define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray + #define TEXTURECUBE(textureName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray + #define TEXTURE3D(textureName) sampler3D textureName + + #define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray + #define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray + #define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + + #define TEXTURE2D_HALF(textureName) sampler2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray + #define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray + #define TEXTURE3D_HALF(textureName) sampler3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + #define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + + #define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + + #define SAMPLER(samplerName) + #define SAMPLER_CMP(samplerName) + + #define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + + #if (SHADER_TARGET >= 30) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) + #else + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) + #endif + + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + + + // Not supported. Can't define as error because shader library is calling these functions. + #define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + + // Gather not supported. Fallback to regular texture sampling. + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + + + + +// default flow control attributes +#ifndef UNITY_BRANCH +# define UNITY_BRANCH +#endif +#ifndef UNITY_FLATTEN +# define UNITY_FLATTEN +#endif +#ifndef UNITY_UNROLL +# define UNITY_UNROLL +#endif +#ifndef UNITY_UNROLLX +# define UNITY_UNROLLX(_x) +#endif +#ifndef UNITY_LOOP +# define UNITY_LOOP +#endif + + + +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + UNITY_POSITION(pos); + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + #ifdef EDITOR_VISUALIZATION + float2 vizUV : TEXCOORD8; + float4 lightCoord : TEXCOORD9; + #endif + + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD17; + // #endif + + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef UNITY_MATRIX_I_M + + #define UNITY_MATRIX_I_M unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)UNITY_MATRIX_V, norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + UNITY_SETUP_INSTANCE_ID(v); + VertexToPixel o; + UNITY_INITIALIZE_OUTPUT(VertexToPixel,o); + UNITY_TRANSFER_INSTANCE_ID(v,o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + + o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #ifdef EDITOR_VISUALIZATION + o.vizUV = 0; + o.lightCoord = 0; + if (unity_VisualizationMode == EDITORVIZ_TEXTURE) + o.vizUV = UnityMetaVizUV(unity_EditorViz_UVIndex, v.texcoord0.xy, v.texcoord1.xy, v.texcoord2.xy, unity_EditorViz_Texture_ST); + else if (unity_VisualizationMode == EDITORVIZ_SHOWLIGHTMASK) + { + o.vizUV = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + o.lightCoord = mul(unity_EditorViz_WorldToLight, mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1))); + } + #endif + + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos); + // #endif + + o.worldPos = mul(GetObjectToWorldMatrix(), v.vertex).xyz; + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + return o; + } + + + + // fragment shader + fixed4 Frag (VertexToPixel IN + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_EXTRACT_FOG_FROM_TSPACE(IN); + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN); + #else + UNITY_EXTRACT_FOG(IN); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + + Surface l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + + ChainSurfaceFunction(l, d); + + UnityMetaInput metaIN; + UNITY_INITIALIZE_OUTPUT(UnityMetaInput, metaIN); + metaIN.Albedo = l.Albedo; + metaIN.Emission = l.Emission; + + #if _USESPECULAR + metaIN.SpecularColor = l.Specular; + #endif + + #ifdef EDITOR_VISUALIZATION + metaIN.VizUV = IN.vizUV; + metaIN.LightCoord = IN.lightCoord; + #endif + return UnityMetaFragment(metaIN); + } + ENDCG + + } + + + + + + } + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_Standard.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_Standard.txt.meta new file mode 100644 index 0000000..4e606d0 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_Standard.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 3d8afde0e2ea785468f09f3f58cf5803 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_Standard.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2019.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2019.txt new file mode 100644 index 0000000..c7736e8 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2019.txt @@ -0,0 +1,4828 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2019 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + + // Keywords + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE + #pragma multi_compile _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS _ADDITIONAL_OFF + #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile _ _SHADOWS_SOFT + #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE + + // GraphKeywords: + + + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define SHADER_PASS SHADERPASS_FORWARD + #define SHADERPASS_FORWARD + + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl" + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD19; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD9; + #endif + float4 fogFactorAndVertexLight : TEXCOORD10; + float4 shadowCoord : TEXCOORD11; + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if _PASSSHADOW + float3 _LightDirection; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + #if _PASSSHADOW + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, _LightDirection)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1, v.texcoord2, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD + OUTPUT_LIGHTMAP_UV(v.texcoord1, unity_LightmapST, o.lightmapUV); + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #if _BAKEDLIT + half3 vertexLight = 0; + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + #endif + half fogFactor = ComputeFogFactor(o.pos.z); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + + #ifdef _MAIN_LIGHT_SHADOWS + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if defined(_USESPECULAR) || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + InputData inputData; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + + #if !_UNLIT + #if _SIMPLELIT + half4 color = UniversalFragmentBlinnPhong( + inputData, + l.Albedo, + float4(specular * l.Smoothness, 0), + l.SpecularPower * 128, + l.Emission, + l.Alpha); + color.a = l.Alpha; + #elif _BAKEDLIT + half4 color = color = UniversalFragmentBakedLit(inputData, l.Albedo, l.Alpha, normalTS); + #else + half4 color = UniversalFragmentPBR( + inputData, + l.Albedo, + metallic, + specular, + l.Smoothness, + l.Occlusion, + l.Emission, + l.Alpha); + #endif + + #else + half4 color = half4(l.Albedo, l.Alpha); + #endif + + #if _UNLITFOG && !DISABLEFOG + color.rgb = MixFog(color.rgb, IN.fogFactorAndVertexLight.x); + #endif + + ChainFinalColorForward(l, d, color); + + return color; + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define SHADERPASS_SHADOWCASTER + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl" + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD19; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD9; + #endif + float4 fogFactorAndVertexLight : TEXCOORD10; + float4 shadowCoord : TEXCOORD11; + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if _PASSSHADOW + float3 _LightDirection; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + #if _PASSSHADOW + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, _LightDirection)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1, v.texcoord2, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD + OUTPUT_LIGHTMAP_UV(v.texcoord1, unity_LightmapST, o.lightmapUV); + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #if _BAKEDLIT + half3 vertexLight = 0; + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + #endif + half fogFactor = ComputeFogFactor(o.pos.z); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + + #ifdef _MAIN_LIGHT_SHADOWS + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2019.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2019.txt.meta new file mode 100644 index 0000000..e613fa2 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2019.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: b6a5f34c034fbd04db605bdcc50b16cd +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2019.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2020.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2020.txt new file mode 100644 index 0000000..69d8931 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2020.txt @@ -0,0 +1,4882 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2020 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Cull Back + Blend One Zero + ZTest LEqual + ZWrite On + + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + + // Keywords + #pragma multi_compile _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE + #pragma multi_compile _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS _ADDITIONAL_OFF + #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile _ _SHADOWS_SOFT + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + // GraphKeywords: + + #define SHADER_PASS SHADERPASS_FORWARD + #define SHADERPASS_FORWARD + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define _PASSFORWARD 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl" + + + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD19; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD9; + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + float4 fogFactorAndVertexLight : TEXCOORD10; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD11; + #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if _PASSSHADOW + float3 _LightDirection; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + #if _PASSSHADOW + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, _LightDirection)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, o.pos.w * UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, o.pos.w * UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #if _BAKEDLIT + half3 vertexLight = 0; + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + #endif + half fogFactor = ComputeFogFactor(o.pos.z); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if _USESPECULAR || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + + + InputData inputData; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos); + #if !_BAKEDLIT + inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector)); + inputData.shadowMask = mulColor; + #endif + #endif + + #if !_UNLIT + #if _SIMPLELIT + half4 color = UniversalFragmentBlinnPhong( + inputData, + l.Albedo, + float4(specular * l.Smoothness, 0), + l.SpecularPower * 128, + l.Emission, + l.Alpha); + color.a = l.Alpha; + #elif _BAKEDLIT + color = UniversalFragmentBakedLit(inputData, l.Albedo, l.Alpha, normalTS); + #else + + + SurfaceData surface = (SurfaceData)0; + surface.albedo = l.Albedo; + surface.metallic = saturate(metallic); + surface.specular = specular; + surface.smoothness = saturate(l.Smoothness), + surface.occlusion = l.Occlusion, + surface.emission = l.Emission, + surface.alpha = saturate(l.Alpha); + surface.clearCoatMask = 0; + surface.clearCoatSmoothness = 1; + + #ifdef _CLEARCOAT + surface.clearCoatMask = saturate(l.CoatMask); + surface.clearCoatSmoothness = saturate(l.CoatSmoothness); + #endif + + half4 color = UniversalFragmentPBR(inputData, surface); + + #endif + + #else + half4 color = half4(l.Albedo, l.Alpha); + + #endif + + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, IN.fogFactorAndVertexLight.x); + #endif + ChainFinalColorForward(l, d, color); + + return color; + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define SHADERPASS_SHADOWCASTER + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl" + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD19; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD9; + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + float4 fogFactorAndVertexLight : TEXCOORD10; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD11; + #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if _PASSSHADOW + float3 _LightDirection; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + #if _PASSSHADOW + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, _LightDirection)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, o.pos.w * UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, o.pos.w * UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #if _BAKEDLIT + half3 vertexLight = 0; + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + #endif + half fogFactor = ComputeFogFactor(o.pos.z); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2020.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2020.txt.meta new file mode 100644 index 0000000..834a3a1 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2020.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 5b690ab8311c671458478ca7f852b720 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2020.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2021.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2021.txt new file mode 100644 index 0000000..cbc61a3 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2021.txt @@ -0,0 +1,4974 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2021 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0 + [HideInInspector]_QueueControl("_QueueControl", Float) = -1 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Cull Back + Blend One Zero + ZTest LEqual + ZWrite On + + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + + // Keywords + #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + #pragma multi_compile_fragment _ _SHADOWS_SOFT + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + //#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 + #pragma multi_compile_fragment _ _LIGHT_LAYERS + #pragma multi_compile_fragment _ DEBUG_DISPLAY + #pragma multi_compile_fragment _ _LIGHT_COOKIES + #pragma multi_compile _ _CLUSTERED_RENDERING + // GraphKeywords: + + #define SHADER_PASS SHADERPASS_FORWARD + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define _PASSFORWARD 1 + #define _FOG_FRAGMENT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + + + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + +#if _UNLIT + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl" +#endif + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if _USESPECULAR || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + + + InputData inputData = (InputData)0; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + +#if _BAKEDLIT + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = 0; +#else + inputData.fogCoord = InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x); + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; +#endif + + + + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #elif _BAKEDLIT + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #else + #if defined(DYNAMICLIGHTMAP_ON) + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS); + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + #endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos); + #if !_BAKEDLIT + inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector)); + inputData.shadowMask = mulColor; + #endif + #else + inputData.shadowMask = float4(1,1,1,1); + #endif + + #if defined(DEBUG_DISPLAY) + #if defined(DYNAMICLIGHTMAP_ON) + inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy; + #endif + #if defined(LIGHTMAP_ON) + inputData.staticLightmapUV = IN.lightmapUV; + #else + inputData.vertexSH = IN.sh; + #endif + #endif + + #if _WORLDSPACENORMAL + float3 normalTS = WorldToTangentSpace(d, l.Normal); + #else + float3 normalTS = l.Normal; + #endif + + SurfaceData surface = (SurfaceData)0; + surface.albedo = l.Albedo; + surface.metallic = saturate(metallic); + surface.specular = specular; + surface.smoothness = saturate(l.Smoothness), + surface.occlusion = l.Occlusion, + surface.emission = l.Emission, + surface.alpha = saturate(l.Alpha); + surface.clearCoatMask = 0; + surface.clearCoatSmoothness = 1; + + #ifdef _CLEARCOAT + surface.clearCoatMask = saturate(l.CoatMask); + surface.clearCoatSmoothness = saturate(l.CoatSmoothness); + #endif + + #if !_UNLIT + half4 color = half4(l.Albedo, l.Alpha); + #ifdef _DBUFFER + #if _BAKEDLIT + half3 bakeColor = color.rgb; + float3 bakeNormal = inputData.normalWS.xyz; + ApplyDecalToBaseColorAndNormal(IN.pos, bakeColor, bakeNormal); + color.rgb = bakeColor; + inputData.normalWS.xyz = bakeNormal; + #else + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + #endif + #if _SIMPLELIT + color = UniversalFragmentBlinnPhong( + inputData, + surface); + #elif _BAKEDLIT + color = UniversalFragmentBakedLit(inputData, color.rgb, color.a, normalTS); + #else + color = UniversalFragmentPBR(inputData, surface); + #endif + + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + + #else // unlit + #ifdef _DBUFFER + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + half4 color = UniversalFragmentUnlit(inputData, l.Albedo, l.Alpha); + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + #endif + ChainFinalColorForward(l, d, color); + + return color; + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW + + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2021.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2021.txt.meta new file mode 100644 index 0000000..8f7d29f --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2021.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: cf43ea038b1b8bc40bb9018effdc2e94 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2021.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2022.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2022.txt new file mode 100644 index 0000000..fc0347b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2022.txt @@ -0,0 +1,5001 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2022 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0 + [HideInInspector]_QueueControl("_QueueControl", Float) = -1 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Cull Back + Blend One Zero + ZTest LEqual + ZWrite On + + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + + // Keywords + #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + #pragma multi_compile_fragment _ _SHADOWS_SOFT + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + //#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 + #pragma multi_compile_fragment _ _LIGHT_LAYERS + #pragma multi_compile_fragment _ DEBUG_DISPLAY + #pragma multi_compile_fragment _ _LIGHT_COOKIES + #pragma multi_compile_fragment _ _WRITE_RENDERING_LAYERS + #pragma multi_compile _ _FORWARD_PLUS + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + // GraphKeywords: + + #define SHADER_PASS SHADERPASS_FORWARD + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define _PASSFORWARD 1 + #define _FOG_FRAGMENT 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + +#if _UNLIT + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl" +#endif + + // fragment shader + void Frag (VertexToPixel IN + , out half4 outColor : SV_Target0 + #ifdef _WRITE_RENDERING_LAYERS + , out float4 outRenderingLayers : SV_Target1 + #endif + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if _USESPECULAR || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + + + InputData inputData = (InputData)0; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + +#if _BAKEDLIT + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = 0; +#else + inputData.fogCoord = InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x); + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; +#endif + + + + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #elif _BAKEDLIT + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #else + #if defined(DYNAMICLIGHTMAP_ON) + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS); + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + #endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos); + #if !_BAKEDLIT + inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector)); + inputData.shadowMask = mulColor; + #endif + #else + inputData.shadowMask = float4(1,1,1,1); + #endif + + #if defined(DEBUG_DISPLAY) + #if defined(DYNAMICLIGHTMAP_ON) + inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy; + #endif + #if defined(LIGHTMAP_ON) + inputData.staticLightmapUV = IN.lightmapUV; + #else + inputData.vertexSH = IN.sh; + #endif + #endif + + #if _WORLDSPACENORMAL + float3 normalTS = WorldToTangentSpace(d, l.Normal); + #else + float3 normalTS = l.Normal; + #endif + + SurfaceData surface = (SurfaceData)0; + surface.albedo = l.Albedo; + surface.metallic = saturate(metallic); + surface.specular = specular; + surface.smoothness = saturate(l.Smoothness), + surface.occlusion = l.Occlusion, + surface.emission = l.Emission, + surface.alpha = saturate(l.Alpha); + surface.clearCoatMask = 0; + surface.clearCoatSmoothness = 1; + + #ifdef _CLEARCOAT + surface.clearCoatMask = saturate(l.CoatMask); + surface.clearCoatSmoothness = saturate(l.CoatSmoothness); + #endif + + #if !_UNLIT + half4 color = half4(l.Albedo, l.Alpha); + #ifdef _DBUFFER + #if _BAKEDLIT + half3 bakeColor = color.rgb; + float3 bakeNormal = inputData.normalWS.xyz; + ApplyDecalToBaseColorAndNormal(IN.pos, bakeColor, bakeNormal); + color.rgb = bakeColor; + inputData.normalWS.xyz = bakeNormal; + #else + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + #endif + #if _SIMPLELIT + color = UniversalFragmentBlinnPhong( + inputData, + surface); + #elif _BAKEDLIT + color = UniversalFragmentBakedLit(inputData, color.rgb, color.a, normalTS); + #else + color = UniversalFragmentPBR(inputData, surface); + #endif + + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + + #else // unlit + #ifdef _DBUFFER + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + half4 color = UniversalFragmentUnlit(inputData, l.Albedo, l.Alpha); + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + #endif + ChainFinalColorForward(l, d, color); + + outColor = color; + + #ifdef _WRITE_RENDERING_LAYERS + #if UNITY_VERSION >= 60020000 + outRenderingLayers = EncodeMeshRenderingLayer(); + #else + uint renderingLayers = GetMeshRenderingLayer(); + outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0); + #endif + #endif + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2022.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2022.txt.meta new file mode 100644 index 0000000..8535f90 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2022.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: ce8330b40cde2f94c9cb20367e34bd3a +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2022.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2023.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2023.txt new file mode 100644 index 0000000..cbf66e1 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2023.txt @@ -0,0 +1,5252 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2023 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLitTransparent_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0 + [HideInInspector]_QueueControl("_QueueControl", Float) = -1 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" } + + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Cull Back + Blend One Zero + ZTest LEqual + ZWrite On + + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + // Keywords + #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + #pragma multi_compile_fragment _ _SHADOWS_SOFT + #pragma multi_compile_fragment _ _SHADOWS_SOFT_LOW + #pragma multi_compile_fragment _ _SHADOWS_SOFT_MEDIUM + #pragma multi_compile_fragment _ _SHADOWS_SOFT_HIGH + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + //#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 + #pragma multi_compile_fragment _ _LIGHT_LAYERS + #pragma multi_compile_fragment _ DEBUG_DISPLAY + #pragma multi_compile_fragment _ _LIGHT_COOKIES + #pragma multi_compile _ _FORWARD_PLUS + #pragma multi_compile _ EVALUATE_SH_VERTEX + #pragma multi_compile _ EVALUATE_SH_MIXED + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + + // GraphKeywords: + + #define SHADER_PASS SHADERPASS_FORWARD + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define _PASSFORWARD 1 + #define _FOG_FRAGMENT 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float4 probeOcclusion : TEXCOORD8; + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float4 previousPositionCS : TEXCOORD21; // Contain previous transform position (in case of skinning for example) + float4 positionCS : TEXCOORD22; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #define GetWorldToViewMatrix() _ViewMatrix + #define UNITY_MATRIX_I_V _InvViewMatrix + #define GetViewToHClipMatrix() OptimizeProjectionMatrix(_ProjMatrix) + #define UNITY_MATRIX_I_P _InvProjMatrix + #define GetWorldToHClipMatrix() _ViewProjMatrix + #define UNITY_MATRIX_I_VP _InvViewProjMatrix + #define UNITY_MATRIX_UNJITTERED_VP _NonJitteredViewProjMatrix + #define UNITY_MATRIX_PREV_VP _PrevViewProjMatrix + #define UNITY_MATRIX_PREV_I_VP _PrevInvViewProjMatrix + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = v; + #endif + #if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); + #endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // This return the camera relative position (if enable) + float3 positionWS = TransformObjectToWorld(v.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(v.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = positionWS; + o.worldNormal = normalWS; + o.worldTangent = tangentWS; + + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + #if UNITY_VERSION < 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #if UNITY_VERSION >= 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + #elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && UNITY_VERSION >= 60000009 + OUTPUT_SH4(vertexInput.positionWS, o.worldNormal.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), o.sh, o.probeOcclusion); + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(o); + #endif + + o.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + if (!forceNoMotion) + { + #if defined(HAVE_VFX_MODIFICATION) + float3 previousPositionOS = currentFrameMvData.vfxParticlePositionOS; + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + const bool applyDeformation = false; + #else + const bool applyDeformation = true; + #endif + #else + const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation + float3 previousPositionOS = hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz; + + #if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT) + const bool applyDeformation = true; + #else + const bool applyDeformation = hasDeformation; + #endif + #endif + // TODO + #if defined(FEATURES_GRAPH_VERTEX) + if (applyDeformation) + previousPositionOS = GetLastFrameDeformedPosition(previousMesh, currentFrameMvData, previousPositionOS); + else + previousPositionOS = previousMesh.positionOS; + + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + #endif + + #if defined(UNITY_DOTS_INSTANCING_ENABLED) && defined(DOTS_DEFORMED) + // Deformed vertices in DOTS are not cumulative with built-in Unity skinning/blend shapes + // Needs to be called after vertex modification has been applied otherwise it will be + // overwritten by Compute Deform node + ApplyPreviousFrameDeformedVertexPosition(previousMesh.vertexID, previousPositionOS); + #endif + #if defined (_ADD_PRECOMPUTED_VELOCITY) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + o.positionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionWS, 1.0f)); + + #if defined(HAVE_VFX_MODIFICATION) + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) || defined(_ADD_PRECOMPUTED_VELOCITY) + #error Unexpected fast path rendering VFX motion vector while there are vertex modification afterwards. + #endif + o.previousPositionCS = VFXGetPreviousClipPosition(previousMesh, currentFrameMvData.vfxElementAttributes, o.positionCS); + #else + #if VFX_WORLD_SPACE + //previousPositionOS is already in world space + const float3 previousPositionWS = previousPositionOS; + #else + const float3 previousPositionWS = mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f)).xyz; + #endif + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionWS, 1.0f)); + #endif + #else + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1))); + #endif + } + #endif + + return o; + } + + + + +#if _UNLIT + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl" +#endif + + // fragment shader + void Frag (VertexToPixel IN + , out half4 outColor : SV_Target0 + #ifdef _WRITE_RENDERING_LAYERS + , out float4 outRenderingLayers : SV_Target1 + #endif + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if _USESPECULAR || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + + + InputData inputData = (InputData)0; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + +#if _BAKEDLIT + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = 0; +#else + inputData.fogCoord = InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x); + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; +#endif + + + + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #elif _BAKEDLIT + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #else + #if defined(DYNAMICLIGHTMAP_ON) + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS); + #elif defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2) + #if UNITY_VERSION >= 60000009 + inputData.bakedGI = SAMPLE_GI(IN.sh, IN.worldPos, inputData.normalWS, inputData.viewDirectionWS, IN.pos, IN.probeOcclusion, inputData.shadowMask); + #else + inputData.bakedGI = SAMPLE_GI(IN.sh, IN.worldPos, inputData.normalWS, inputData.viewDirectionWS, IN.pos); + #endif + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + #endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos); + #if !_BAKEDLIT + inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector)); + inputData.shadowMask = mulColor; + #endif + #else + inputData.shadowMask = float4(1,1,1,1); + #endif + + #if defined(DEBUG_DISPLAY) + #if defined(DYNAMICLIGHTMAP_ON) + inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy; + #endif + #if defined(LIGHTMAP_ON) + inputData.staticLightmapUV = IN.lightmapUV; + #else + inputData.vertexSH = IN.sh; + #endif + #endif + + #if _WORLDSPACENORMAL + float3 normalTS = WorldToTangentSpace(d, l.Normal); + #else + float3 normalTS = l.Normal; + #endif + + SurfaceData surface = (SurfaceData)0; + surface.albedo = l.Albedo; + surface.metallic = saturate(metallic); + surface.specular = specular; + surface.smoothness = saturate(l.Smoothness), + surface.occlusion = l.Occlusion, + surface.emission = l.Emission, + surface.alpha = saturate(l.Alpha); + surface.clearCoatMask = 0; + surface.clearCoatSmoothness = 1; + + #ifdef _CLEARCOAT + surface.clearCoatMask = saturate(l.CoatMask); + surface.clearCoatSmoothness = saturate(l.CoatSmoothness); + #endif + + #if !_UNLIT + half4 color = half4(l.Albedo, l.Alpha); + #ifdef _DBUFFER + #if _BAKEDLIT + half3 bakeColor = color.rgb; + float3 bakeNormal = inputData.normalWS.xyz; + ApplyDecalToBaseColorAndNormal(IN.pos, bakeColor, bakeNormal); + color.rgb = bakeColor; + inputData.normalWS.xyz = bakeNormal; + #else + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + #endif + #if _SIMPLELIT + color = UniversalFragmentBlinnPhong( + inputData, + surface); + #elif _BAKEDLIT + color = UniversalFragmentBakedLit(inputData, color.rgb, color.a, normalTS); + #else + color = UniversalFragmentPBR(inputData, surface); + #endif + + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + + #else // unlit + #ifdef _DBUFFER + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + half4 color = UniversalFragmentUnlit(inputData, l.Albedo, l.Alpha); + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + #endif + ChainFinalColorForward(l, d, color); + + outColor = color; + + #ifdef _WRITE_RENDERING_LAYERS + #if UNITY_VERSION >= 60020000 + outRenderingLayers = EncodeMeshRenderingLayer(); + #else + uint renderingLayers = GetMeshRenderingLayer(); + outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0); + #endif + #endif + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float4 probeOcclusion : TEXCOORD8; + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float4 previousPositionCS : TEXCOORD21; // Contain previous transform position (in case of skinning for example) + float4 positionCS : TEXCOORD22; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #define GetWorldToViewMatrix() _ViewMatrix + #define UNITY_MATRIX_I_V _InvViewMatrix + #define GetViewToHClipMatrix() OptimizeProjectionMatrix(_ProjMatrix) + #define UNITY_MATRIX_I_P _InvProjMatrix + #define GetWorldToHClipMatrix() _ViewProjMatrix + #define UNITY_MATRIX_I_VP _InvViewProjMatrix + #define UNITY_MATRIX_UNJITTERED_VP _NonJitteredViewProjMatrix + #define UNITY_MATRIX_PREV_VP _PrevViewProjMatrix + #define UNITY_MATRIX_PREV_I_VP _PrevInvViewProjMatrix + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = v; + #endif + #if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); + #endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // This return the camera relative position (if enable) + float3 positionWS = TransformObjectToWorld(v.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(v.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = positionWS; + o.worldNormal = normalWS; + o.worldTangent = tangentWS; + + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + #if UNITY_VERSION < 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #if UNITY_VERSION >= 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + #elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && UNITY_VERSION >= 60000009 + OUTPUT_SH4(vertexInput.positionWS, o.worldNormal.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), o.sh, o.probeOcclusion); + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(o); + #endif + + o.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + if (!forceNoMotion) + { + #if defined(HAVE_VFX_MODIFICATION) + float3 previousPositionOS = currentFrameMvData.vfxParticlePositionOS; + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + const bool applyDeformation = false; + #else + const bool applyDeformation = true; + #endif + #else + const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation + float3 previousPositionOS = hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz; + + #if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT) + const bool applyDeformation = true; + #else + const bool applyDeformation = hasDeformation; + #endif + #endif + // TODO + #if defined(FEATURES_GRAPH_VERTEX) + if (applyDeformation) + previousPositionOS = GetLastFrameDeformedPosition(previousMesh, currentFrameMvData, previousPositionOS); + else + previousPositionOS = previousMesh.positionOS; + + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + #endif + + #if defined(UNITY_DOTS_INSTANCING_ENABLED) && defined(DOTS_DEFORMED) + // Deformed vertices in DOTS are not cumulative with built-in Unity skinning/blend shapes + // Needs to be called after vertex modification has been applied otherwise it will be + // overwritten by Compute Deform node + ApplyPreviousFrameDeformedVertexPosition(previousMesh.vertexID, previousPositionOS); + #endif + #if defined (_ADD_PRECOMPUTED_VELOCITY) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + o.positionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionWS, 1.0f)); + + #if defined(HAVE_VFX_MODIFICATION) + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) || defined(_ADD_PRECOMPUTED_VELOCITY) + #error Unexpected fast path rendering VFX motion vector while there are vertex modification afterwards. + #endif + o.previousPositionCS = VFXGetPreviousClipPosition(previousMesh, currentFrameMvData.vfxElementAttributes, o.positionCS); + #else + #if VFX_WORLD_SPACE + //previousPositionOS is already in world space + const float3 previousPositionWS = previousPositionOS; + #else + const float3 previousPositionWS = mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f)).xyz; + #endif + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionWS, 1.0f)); + #endif + #else + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1))); + #endif + } + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + + + } + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2023.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2023.txt.meta new file mode 100644 index 0000000..9baf927 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2023.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: b3fd67a7feee2e848b1efa22e4d324c0 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLitTransparent_BetterShader_URP2023.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader.surfshader b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader.surfshader new file mode 100644 index 0000000..3129cd4 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader.surfshader @@ -0,0 +1,1384 @@ +BEGIN_OPTIONS + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" + ShaderName "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +END_OPTIONS + +BEGIN_PROPERTIES + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 +END_PROPERTIES + + +BEGIN_DEFINES + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + +END_DEFINES + +BEGIN_CBUFFER + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + +END_CBUFFER + +BEGIN_PASS("Forward") + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] +END_PASS + +BEGIN_PASS("GBuffer") + Cull [_CullingOption] +END_PASS + +BEGIN_CODE + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void ModifyVertex(inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void SurfaceFunction(inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + +END_CODE \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader.surfshader.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader.surfshader.meta new file mode 100644 index 0000000..15e1b8d --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader.surfshader.meta @@ -0,0 +1,17 @@ +fileFormatVersion: 2 +guid: 325f1e8448719734a8a423b1dec4f03a +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: ed1b96e11e9064957833ce8c01da6f92, type: 3} +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader.surfshader + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2019.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2019.txt new file mode 100644 index 0000000..50e6685 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2019.txt @@ -0,0 +1,16505 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: HDRP2019 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + + [HideInInspector] _StencilRef("Vector1 ", Int) = 0 + [HideInInspector] _StencilWriteMask("Vector1 ", Int) = 3 + [HideInInspector] _StencilRefDepth("Vector1 ", Int) = 0 + [HideInInspector] _StencilWriteMaskDepth("Vector1 ", Int) = 32 + [HideInInspector] _StencilRefMV("Vector1 ", Int) = 128 + [HideInInspector] _StencilWriteMaskMV("Vector1 ", Int) = 128 + [HideInInspector] _StencilRefDistortionVec("Vector1 ", Int) = 64 + [HideInInspector] _StencilWriteMaskDistortionVec("Vector1 ", Int) = 64 + [HideInInspector] _StencilWriteMaskGBuffer("Vector1 ", Int) = 3 + [HideInInspector] _StencilRefGBuffer("Vector1 ", Int) = 2 + [HideInInspector] _ZTestGBuffer("Vector1 ", Int) = 4 + [HideInInspector] [ToggleUI] _RequireSplitLighting("Boolean", Float) = 0 + [HideInInspector] [ToggleUI] _ReceivesSSR("Boolean", Float) = 1 + [HideInInspector] _SurfaceType("Vector1 ", Float) = 0 + [HideInInspector] [ToggleUI] _ZWrite("Boolean", Float) = 0 + [HideInInspector] _TransparentSortPriority("Vector1 ", Int) = 0 + [HideInInspector] _ZTestDepthEqualForOpaque("Vector1 ", Int) = 4 + [HideInInspector] [Enum(UnityEngine.Rendering.CompareFunction)] _ZTestTransparent("Vector1", Float) = 4 + [HideInInspector] [ToggleUI] _TransparentBackfaceEnable("Boolean", Float) = 0 + [HideInInspector] [ToggleUI] _AlphaCutoffEnable("Boolean", Float) = 0 + [HideInInspector] [ToggleUI] _UseShadowThreshold("Boolean", Float) = 0 + [HideInInspector] _BlendMode("Float", Float) = 0 + } + SubShader + { + Tags { "RenderPipeline"="HDRenderPipeline" "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" "Queue" = "Geometry+225" } + + + Pass + { + // based on HDLitPass.template + Name "Forward" + Tags { "LightMode" = "Forward" } + + + + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMask] + Ref [_StencilRef] + Comp Always + Pass Replace + } + + ColorMask [_ColorMaskTransparentVel] 1 + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + // #pragma multi_compile _ LOD_FADE_CROSSFADE + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADDITIVE _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_FORWARD + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + #pragma multi_compile _ DEBUG_DISPLAY + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ SHADOWS_SHADOWMASK + #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST + #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #define REQUIRE_DEPTH_TEXTURE + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + + void Frag(PackedVaryingsToPS packedInput, + #ifdef OUTPUT_SPLIT_LIGHTING + out float4 outColor : SV_Target0, // outSpecularLighting + out float4 outDiffuseLighting : SV_Target1, + OUTPUT_SSSBUFFER(outSSSBuffer) + #else + out float4 outColor : SV_Target0 + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + , out float4 outMotionVec : SV_Target1 + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + #endif // OUTPUT_SPLIT_LIGHTING + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + // Init outMotionVector here to solve compiler warning (potentially unitialized variable) + // It is init to the value of forceNoMotion (with 2.0) + outMotionVec = float4(2.0, 0.0, 0.0, 0.0); + #endif + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer. + input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy; + + uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + + PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); + + outColor = float4(0.0, 0.0, 0.0, 0.0); + + // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. + + #ifdef DEBUG_DISPLAY + // Init in debug display mode to quiet warning + #ifdef OUTPUT_SPLIT_LIGHTING + outDiffuseLighting = 0; + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #endif + + + + // Same code in ShaderPassForwardUnlit.shader + // Reminder: _DebugViewMaterialArray[i] + // i==0 -> the size used in the buffer + // i>0 -> the index used (0 value means nothing) + // The index stored in this buffer could either be + // - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported) + // - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty) + bool viewMaterial = false; + int bufferSize = int(_DebugViewMaterialArray[0]); + if (bufferSize != 0) + { + bool needLinearToSRGB = false; + float3 result = float3(1.0, 0.0, 1.0); + + // Loop through the whole buffer + // Works because GetSurfaceDataDebug will do nothing if the index is not a known one + for (int index = 1; index <= bufferSize; index++) + { + int indexMaterialProperty = int(_DebugViewMaterialArray[index]); + + // skip if not really in use + if (indexMaterialProperty != 0) + { + viewMaterial = true; + + GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB); + GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB); + GetBuiltinDataDebug(indexMaterialProperty, builtinData, result, needLinearToSRGB); + GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB); + GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB); + } + } + + // TEMP! + // For now, the final blit in the backbuffer performs an sRGB write + // So in the meantime we apply the inverse transform to linear data to compensate. + if (!needLinearToSRGB) + result = SRGBToLinear(max(0, result)); + + outColor = float4(result, 1.0); + } + + if (!viewMaterial) + { + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR) + { + float3 result = float3(0.0, 0.0, 0.0); + + GetPBRValidatorDebug(surfaceData, result); + + outColor = float4(result, 1.0f); + } + else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) + { + float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A); + outColor = result; + } + else + #endif + { + #ifdef _SURFACE_TYPE_TRANSPARENT + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; + #else + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; + #endif + + float3 diffuseLighting; + float3 specularLighting; + + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + { + LightLoopOutput lightLoopOutput; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput); + + // Alias + diffuseLighting = lightLoopOutput.diffuseLighting; + specularLighting = lightLoopOutput.specularLighting; + } + #else + { + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting); + } + #endif + + diffuseLighting *= GetCurrentExposureMultiplier(); + specularLighting *= GetCurrentExposureMultiplier(); + + #ifdef OUTPUT_SPLIT_LIGHTING + if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) + { + outColor = float4(specularLighting, 1.0); + outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); + } + else + { + outColor = float4(diffuseLighting + specularLighting, 1.0); + outDiffuseLighting = 0; + } + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #else + outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); + outColor = EvaluateAtmosphericScattering(posInput, V, outColor); + #endif + + ChainFinalColorForward(l, d, outColor); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + VaryingsPassToPS inputPass = UnpackVaryingsPassToPS(packedInput.vpass); + bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0); + // outMotionVec is already initialize at the value of forceNoMotion (see above) + if (!forceNoMotion) + { + float2 motionVec = CalculateMotionVector(inputPass.positionCS, inputPass.previousPositionCS); + EncodeMotionVector(motionVec * 0.5, outMotionVec); + outMotionVec.zw = 1.0; + } + #endif + } + + #ifdef DEBUG_DISPLAY + } + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "GBuffer" + Tags { "LightMode" = "GBuffer" } + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + ZTest [_ZTestGBuffer] + + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskGBuffer] + Ref [_StencilRefGBuffer] + Comp Always + Pass Replace + } + Cull [_CullingOption] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + #define SHADERPASS SHADERPASS_GBUFFER + #pragma multi_compile _ DEBUG_DISPLAY + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ SHADOWS_SHADOWMASK + #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile _ LIGHT_LAYERS + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + void Frag( PackedVaryingsToPS packedInput, + OUTPUT_GBUFFER(outGBuffer) + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + ZClip [_ZClip] + ZWrite On + ZTest LEqual + + ColorMask 0 + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_SHADOWS + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + + + void Frag( PackedVaryingsToPS packedInput + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "META" + Tags { "LightMode" = "META" } + + Cull Off + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + #define _PASSMETA 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + + float4 Frag(PackedVaryingsToPS packedInput + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + + ) : SV_Target + { + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // no debug apply during light transport pass + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); + + // This shader is call two times. Once for getting emissiveColor, the other time to get diffuseColor + // We use unity_MetaFragmentControl to make the distinction. + float4 res = float4(0.0, 0.0, 0.0, 1.0); + + if (unity_MetaFragmentControl.x) + { + // Apply diffuseColor Boost from LightmapSettings. + // put abs here to silent a warning, no cost, no impact as color is assume to be positive. + res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); + } + + if (unity_MetaFragmentControl.y) + { + // emissive use HDR format + res.rgb = lightTransportData.emissiveColor; + } + + return res; + } + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + ColorMask 0 + + + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENESELECTIONPASS + #pragma editor_sync_compilation + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSSCENESELECT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + + + void Frag( PackedVaryingsToPS packedInput + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + Pass + { + // based on HDLitPass.template + Name "DepthOnly" + Tags { "LightMode" = "DepthOnly" } + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + + ZWrite On + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskDepth] + Ref [_StencilRefDepth] + Comp Always + Pass Replace + } + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + // #pragma multi_compile _ LOD_FADE_CROSSFADE + + //#pragma shader_feature _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSDEPTH 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + + // define FragInputs structure + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" + #endif + + + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + + #if (SHADERPASS == SHADERPASS_FORWARD) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + + #define HAS_LIGHTLOOP + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #endif + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + // Used by SceneSelectionPass + int _ObjectId; + int _PassValue; + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + CBUFFER_START(UnityPerMaterial) + float _StencilRef; + float _StencilWriteMask; + float _StencilRefDepth; + float _StencilWriteMaskDepth; + float _StencilRefMV; + float _StencilWriteMaskMV; + float _StencilRefDistortionVec; + float _StencilWriteMaskDistortionVec; + float _StencilWriteMaskGBuffer; + float _StencilRefGBuffer; + float _ZTestGBuffer; + float _RequireSplitLighting; + float _ReceivesSSR; + float _ZWrite; + float _TransparentSortPriority; + float _ZTestDepthEqualForOpaque; + float _ZTestTransparent; + float _TransparentBackfaceEnable; + float _AlphaCutoffEnable; + float _UseShadowThreshold; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +struct VaryingsToPS +{ + VertexToPixel vmesh; + #ifdef VARYINGS_NEED_PASS + VaryingsPassToPS vpass; + #endif +}; + +struct PackedVaryingsToPS +{ + #ifdef VARYINGS_NEED_PASS + PackedVaryingsPassToPS vpass; + #endif + VertexToPixel vmesh; + + UNITY_VERTEX_OUTPUT_STEREO +}; + +PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) +{ + PackedVaryingsToPS output = (PackedVaryingsToPS)0; + output.vmesh = input.vmesh; + #ifdef VARYINGS_NEED_PASS + output.vpass = PackVaryingsPassToPS(input.vpass); + #endif + + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + return output; +} + + + + +VertexToPixel VertMesh(VertexData input) +{ + VertexToPixel output = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + + + ChainModifyVertex(input, output, _Time); + + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + return output; +} + + +#if (SHADERPASS == SHADERPASS_DBUFFER_MESH) +void MeshDecalsPositionZBias(inout VaryingsToPS input) +{ +#if defined(UNITY_REVERSED_Z) + input.vmesh.pos.z -= _DecalMeshDepthBias; +#else + input.vmesh.pos.z += _DecalMeshDepthBias; +#endif +} +#endif + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + +// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency +float unity_OneOverOutputBoost; +float unity_MaxOutputValue; + +CBUFFER_START(UnityMetaPass) +// x = use uv1 as raster position +// y = use uv2 as raster position +bool4 unity_MetaVertexControl; + +// x = return albedo +// y = return normal +bool4 unity_MetaFragmentControl; +CBUFFER_END + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS output = (VaryingsToPS)0; + output.vmesh = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output.vmesh); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.vmesh.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + +#ifdef VARYINGS_NEED_POSITION_WS + output.vmesh.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz); +#endif + +#ifdef VARYINGS_NEED_TANGENT_TO_WORLD + // Normal is required for triplanar mapping + output.vmesh.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.vmesh.worldTangent = float4(1.0, 0.0, 0.0, 0.0); +#endif + + output.vmesh.texcoord0 = inputMesh.texcoord0; + output.vmesh.texcoord1 = inputMesh.texcoord1; + output.vmesh.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.vmesh.texcoord3 = inputMesh.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vmesh.vertexColor = inputMesh.vertexColor; + // #endif + + return PackVaryingsToPS(output); +} +#else + +PackedVaryingsToPS Vert(VertexData inputMesh) +{ + VaryingsToPS varyingsType; + varyingsType.vmesh = VertMesh(inputMesh); + #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) + MeshDecalsPositionZBias(varyingsType); + #endif + return PackVaryingsToPS(varyingsType); +} + +#endif + + + + + + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + #ifdef _HAS_REFRACTION + if (_EnableSSRefraction) + { + // surfaceData.ior = surfaceDescription.RefractionIndex; + // surfaceData.transmittanceColor = surfaceDescription.RefractionColor; + // surfaceData.atDistance = surfaceDescription.RefractionDistance; + + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + // surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + // tangent-space normal + float3 normalTS = float3(0.0f, 0.0f, 1.0f); + normalTS = surfaceDescription.Normal; + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(normalTS, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = normalTS; + #endif + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + // surfaceData.tangentWS = TransformTangentToWorld(surfaceDescription.Tangent, fragInputs.tangentToWorld); + + #if HAVE_DECALS + if (_EnableDecals) + { + #if VERSION_GREATER_EQUAL(10,2) + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceData.geomNormalWS, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData.geomNormalWS, surfaceData); + #else + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); + #endif + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #ifdef _ENABLE_GEOMETRIC_SPECULAR_AA + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // uint3 fadeMaskSeed = asuint((int3)(V * _ScreenSize.xyx)); // Quantize V to _ScreenSize values + // LODDitheringTransition(fadeMaskSeed, unity_LODFade.x); + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = posInput.deviceDepth; + #endif + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceDescription.Distortion; + //builtinData.distortionBlur = surfaceDescription.DistortionBlur; + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #else + builtinData.distortion = float2(0.0, 0.0); + builtinData.distortionBlur = 0.0; + #endif + + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + } + + + void Frag( PackedVaryingsToPS packedInput + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); + FragInputs input = BuildFragInputs(packedInput.vmesh); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(packedInput.vmesh, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // to prevent stripping + surfaceData.normalWS *= saturate(l.Albedo.r + 9999); + + + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = packedInput.vmesh.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + + + + + } + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2019.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2019.txt.meta new file mode 100644 index 0000000..11ef709 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2019.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: e25ae0d994e4df1408dc1cbf96a8adf3 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2019.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2020.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2020.txt new file mode 100644 index 0000000..9965de8 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2020.txt @@ -0,0 +1,25148 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: HDRP2020 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + + [HideInInspector]_RenderQueueType("Float", Float) = 1 + [HideInInspector][ToggleUI]_AddPrecomputedVelocity("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_DepthOffsetEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentWritingMotionVec("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaCutoffEnable("Boolean", Float) = 0 + [HideInInspector]_TransparentSortPriority("_TransparentSortPriority", Float) = 0 + [HideInInspector][ToggleUI]_UseShadowThreshold("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPrepassEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPostpassEnable("Boolean", Float) = 0 + [HideInInspector]_SurfaceType("Float", Float) = 0 + [HideInInspector]_BlendMode("Float", Float) = 0 + [HideInInspector]_SrcBlend("Float", Float) = 1 + [HideInInspector]_DstBlend("Float", Float) = 0 + [HideInInspector]_AlphaSrcBlend("Float", Float) = 1 + [HideInInspector]_AlphaDstBlend("Float", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMask("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMaskInspectorValue("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ZWrite("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_TransparentZWrite("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableFogOnTransparent("Boolean", Float) = 1 + [HideInInspector]_ZTestDepthEqualForOpaque("Float", Int) = 4 + [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestTransparent("Float", Float) = 4 + [HideInInspector][ToggleUI]_TransparentBackfaceEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_RequireSplitLighting("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ReceivesSSR("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_ReceivesSSRTransparent("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableBlendModePreserveSpecularLighting("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_SupportDecals("Boolean", Float) = 1 + [HideInInspector]_StencilRef("Float", Int) = 0 + [HideInInspector]_StencilWriteMask("Float", Int) = 6 + [HideInInspector]_StencilRefDepth("Float", Int) = 8 + [HideInInspector]_StencilWriteMaskDepth("Float", Int) = 8 + [HideInInspector]_StencilRefMV("Float", Int) = 40 + [HideInInspector]_StencilWriteMaskMV("Float", Int) = 40 + [HideInInspector]_StencilRefDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskGBuffer("Float", Int) = 14 + [HideInInspector]_StencilRefGBuffer("Float", Int) = 10 + [HideInInspector]_ZTestGBuffer("Float", Int) = 4 + [HideInInspector][ToggleUI]_RayTracing("Boolean", Float) = 0 + [HideInInspector][Enum(None, 0, Box, 1, Sphere, 2, Thin, 3)]_RefractionModel("Float", Float) = 0 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" "Queue" = "Geometry+225" } + + + Pass + { + // based on HDLitPass.template + Name "Forward" + Tags { "LightMode" = "Forward" } + + + + Stencil + { + WriteMask [_StencilWriteMask] + Ref [_StencilRef] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + ColorMask [_ColorMaskTransparentVel] 1 + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ SHADOWS_SHADOWMASK + #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON + #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_FORWARD + #define SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING + #define HAS_LIGHTLOOP + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #ifdef UNITY_VIRTUAL_TEXTURING + #define VT_BUFFER_TARGET SV_Target1 + #define EXTRA_BUFFER_TARGET SV_Target2 + #else + #define EXTRA_BUFFER_TARGET SV_Target1 + #endif + + + + + void Frag(VertexToPixel v2p, + #ifdef OUTPUT_SPLIT_LIGHTING + out float4 outColor : SV_Target0, // outSpecularLighting + #ifdef UNITY_VIRTUAL_TEXTURING + out float4 outVTFeedback : VT_BUFFER_TARGET, + #endif + out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET, + OUTPUT_SSSBUFFER(outSSSBuffer) + #else + out float4 outColor : SV_Target0 + #ifdef UNITY_VIRTUAL_TEXTURING + ,out float4 outVTFeedback : VT_BUFFER_TARGET + #endif + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + , out float4 outMotionVec : EXTRA_BUFFER_TARGET + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + #endif // OUTPUT_SPLIT_LIGHTING + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + // Init outMotionVector here to solve compiler warning (potentially unitialized variable) + // It is init to the value of forceNoMotion (with 2.0) + outMotionVec = float4(2.0, 0.0, 0.0, 0.0); + #endif + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer. + input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy; + + uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + + PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); + + outColor = float4(0.0, 0.0, 0.0, 0.0); + + // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. + + #ifdef DEBUG_DISPLAY + // Init in debug display mode to quiet warning + #ifdef OUTPUT_SPLIT_LIGHTING + outDiffuseLighting = 0; + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #endif + + + + // Same code in ShaderPassForwardUnlit.shader + // Reminder: _DebugViewMaterialArray[i] + // i==0 -> the size used in the buffer + // i>0 -> the index used (0 value means nothing) + // The index stored in this buffer could either be + // - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported) + // - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty) + bool viewMaterial = false; + int bufferSize = _DebugViewMaterialArray[0].x; + if (bufferSize != 0) + { + bool needLinearToSRGB = false; + float3 result = float3(1.0, 0.0, 1.0); + + // Loop through the whole buffer + // Works because GetSurfaceDataDebug will do nothing if the index is not a known one + for (int index = 1; index <= bufferSize; index++) + { + int indexMaterialProperty = _DebugViewMaterialArray[index].x; + + // skip if not really in use + if (indexMaterialProperty != 0) + { + viewMaterial = true; + + GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB); + GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB); + GetBuiltinDataDebug(indexMaterialProperty, builtinData, posInput, result, needLinearToSRGB); + GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB); + GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB); + } + } + + // TEMP! + // For now, the final blit in the backbuffer performs an sRGB write + // So in the meantime we apply the inverse transform to linear data to compensate. + if (!needLinearToSRGB) + result = SRGBToLinear(max(0, result)); + + outColor = float4(result, 1.0); + } + + if (!viewMaterial) + { + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR) + { + float3 result = float3(0.0, 0.0, 0.0); + + GetPBRValidatorDebug(surfaceData, result); + + outColor = float4(result, 1.0f); + } + else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) + { + float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A); + outColor = result; + } + else + #endif + { + #ifdef _SURFACE_TYPE_TRANSPARENT + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; + #else + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; + #endif + + LightLoopOutput lightLoopOutput; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput); + + float3 diffuseLighting = lightLoopOutput.diffuseLighting; + float3 specularLighting = lightLoopOutput.specularLighting; + + diffuseLighting *= GetCurrentExposureMultiplier(); + specularLighting *= GetCurrentExposureMultiplier(); + + #ifdef OUTPUT_SPLIT_LIGHTING + if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) + { + outColor = float4(specularLighting, 1.0); + outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); + } + else + { + outColor = float4(diffuseLighting + specularLighting, 1.0); + outDiffuseLighting = 0; + } + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #else + outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); + outColor = EvaluateAtmosphericScattering(posInput, V, outColor); + #endif + + ChainFinalColorForward(l, d, outColor); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0); + // outMotionVec is already initialize at the value of forceNoMotion (see above) + if (!forceNoMotion) + { + float2 motionVec = CalculateMotionVector(v2p.motionVectorCS, v2p.previousPositionCS); + EncodeMotionVector(motionVec * 0.5, outMotionVec); + outMotionVec.zw = 1.0; + } + #endif + } + + #ifdef DEBUG_DISPLAY + } + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + outVTFeedback = builtinData.vtPackedFeedback; + #endif + } + + ENDHLSL + } + Pass + { + // based on HDLitPass.template + Name "GBuffer" + Tags { "LightMode" = "GBuffer" } + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZTest [_ZTestGBuffer] + Stencil + { + WriteMask [_StencilWriteMaskGBuffer] + Ref [_StencilRefGBuffer] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + Cull [_CullingOption] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + + #pragma multi_compile _ LIGHT_LAYERS + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ SHADOWS_SHADOWMASK + #pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_GBUFFER + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + void Frag( VertexToPixel v2f, + OUTPUT_GBUFFER(outGBuffer) + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZWrite On + ColorMask 0 + ZClip [_ZClip] + + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_SHADOWS + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + #endif + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + + + } + + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "DepthOnly" + Tags { "LightMode" = "DepthOnly" } + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + + ZWrite On + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskDepth] + Ref [_StencilRefDepth] + Comp Always + Pass Replace + } + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSDEPTH 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2p + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + // to prevent stripping + surfaceData.normalWS *= saturate(l.Albedo.r + 9999); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + } + + + + ENDHLSL + } + + + + Pass + { + // based on HDLitPass.template + Name "META" + Tags { "LightMode" = "META" } + + Cull Off + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 ps4 xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + #define _PASSMETA 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + float4 Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // no debug apply during light transport pass + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); + + // This shader is call two times. Once for getting emissiveColor, the other time to get diffuseColor + // We use unity_MetaFragmentControl to make the distinction. + float4 res = float4(0.0, 0.0, 0.0, 1.0); + + if (unity_MetaFragmentControl.x) + { + // Apply diffuseColor Boost from LightmapSettings. + // put abs here to silent a warning, no cost, no impact as color is assume to be positive. + res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); + } + + if (unity_MetaFragmentControl.y) + { + // emissive use HDR format + res.rgb = lightTransportData.emissiveColor; + } + + return res; + } + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + Cull Off + ColorMask 0 + + + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define SCENESELECTIONPASS + #define _PASSSCENESELECT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + void Frag( VertexToPixel IN + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + FragInputs input = BuildFragInputs(IN); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(IN, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + Pass + { + Name "ScenePickingPass" + Tags + { + "LightMode" = "Picking" + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENEPICKINGPASS + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + + } + + ENDHLSL + } + + Pass + { + Name "MotionVectors" + Tags + { + "LightMode" = "MotionVectors" + } + + // Render State + Cull Back + ZWrite On + Stencil + { + WriteMask [_StencilWriteMaskMV] + Ref [_StencilRefMV] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + + #pragma multi_compile _ WRITE_MSAA_DEPTH + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ WRITE_NORMAL_BUFFER + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ WRITE_DECAL_BUFFER + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_MOTION_VECTORS + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define VARYINGS_NEED_PASS + #define _PASSMOTIONVECTOR 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#if defined(WRITE_DECAL_BUFFER) && defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target3 +#elif defined(WRITE_DECAL_BUFFER) || defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target2 +#else +#define SV_TARGET_NORMAL SV_Target1 +#endif + +// Caution: Motion vector pass is different from Depth prepass, it render normal buffer last instead of decal buffer last +// and thus, we force a write of 0 if _DISABLE_DECALS so we always write in the decal buffer. +// This is required as we can't make distinction between deferred (write normal buffer) and forward (write normal buffer) +// in the context of the motion vector pass. The cost is acceptable as it is only do object with motion vector (usualy skin object) +// that most of the time use Forward Material (so are already writing motion vector data). +// So note that here unlike for depth prepass we don't check && !defined(_DISABLE_DECALS) +void Frag( VertexToPixel v2f + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + , out float4 outMotionVector : SV_Target1 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target2 + #endif + #else + // When no MSAA, the motion vector is always the first buffer + , out float4 outMotionVector : SV_Target0 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target1 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_TARGET_NORMAL + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + + FragInputs input = BuildFragInputs(v2f); + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + #ifdef _DEPTHOFFSET_ON + v2f.motionVectorCS.w += builtinData.depthOffset; + v2f.previousPositionCS.w += builtinData.depthOffset; + #endif + + // TODO: How to allow overriden motion vector from GetSurfaceAndBuiltinData ? + float2 motionVector = CalculateMotionVector(v2f.motionVectorCS, v2f.previousPositionCS); + + // Convert from Clip space (-1..1) to NDC 0..1 space. + // Note it doesn't mean we don't have negative value, we store negative or positive offset in NDC space. + // Note: ((positionCS * 0.5 + 0.5) - (v2f.previousPositionCS * 0.5 + 0.5)) = (motionVector * 0.5) + EncodeMotionVector(motionVector * 0.5, outMotionVector); + + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + // Setting the motionVector to a value more than 2 set as a flag for "force no motion". This is valid because, given that the velocities are in NDC, + // a value of >1 can never happen naturally, unless explicitely set. + if (forceNoMotion) + outMotionVector = float4(2.0, 0.0, 0.0, 0.0); + + // Depth and Alpha to coverage + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif + #endif + + // Normal Buffer Processing + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) + DecalPrepassData decalPrepassData; + // Force a write in decal buffer even if decal is disab. This is a neutral value which have no impact for later pass + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + #endif + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + + Pass + { + Name "FullScreenDebug" + Tags + { + "LightMode" = "FullScreenDebug" + } + + // Render State + Cull Back + ZTest LEqual + ZWrite Off + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_FULL_SCREEN_DEBUG + #define _PASSFULLSCREENDEBUG 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" // Need to be here for Gradient struct definition + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex); + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // copy before user modification, since we'll apply that to the copy later + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + #if defined(_ENABLE_SHADOW_MATTE) && SHADERPASS == SHADERPASS_FORWARD_UNLIT + HDShadowContext shadowContext = InitShadowContext(); + float shadow; + float3 shadow3; + // We need to recompute some coordinate not computed by default for shadow matte + posInput = GetPositionInput(fragInputs.positionSS.xy, _ScreenSize.zw, fragInputs.positionSS.z, UNITY_MATRIX_I_VP, GetWorldToViewMatrix()); + float3 upWS = normalize(fragInputs.tangentToWorld[1]); + uint renderingLayers = GetMeshRenderingLightLayer(); + ShadowLoopMin(shadowContext, posInput, upWS, asuint(_ShadowMatteFilter), renderingLayers, shadow3); + shadow = dot(shadow3, float3(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)); + + float4 shadowColor = (1.0 - shadow) * surfaceDescription.ShadowTint.rgba; + float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + + // Keep the nested lerp + // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow + // And mix color to consider the Color & ShadowColor alpha (from texture or/and color picker) + #ifdef _SURFACE_TYPE_TRANSPARENT + surfaceData.baseColor = lerp(shadowColor.rgb * surfaceData.baseColor, lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow), surfaceDescription.Alpha); + #else + surfaceData.baseColor = lerp(lerp(shadowColor.rgb, surfaceData.baseColor, 1.0 - surfaceDescription.ShadowTint.a), surfaceData.baseColor, shadow); + #endif + localAlpha = ApplyBlendMode(surfaceData.baseColor, localAlpha).a; + + surfaceDescription.Alpha = localAlpha; + #endif + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + //builtinData.distortion = surfaceData.Distortion; + //builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#define DEBUG_DISPLAY +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/FullScreenDebug.hlsl" + + #if !defined(_DEPTHOFFSET_ON) + [earlydepthstencil] // quad overshading debug mode writes to UAV + #endif + void Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz); + + #ifdef PLATFORM_SUPPORTS_PRIMITIVE_ID_IN_PIXEL_SHADER + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_QUAD_OVERDRAW) + { + IncrementQuadOverdrawCounter(posInput.positionSS.xy, input.primitiveID); + } + #endif + } + + ENDHLSL + } + + + + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2020.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2020.txt.meta new file mode 100644 index 0000000..c52b706 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2020.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: b8403357ed2de81489de24747f4c4e40 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2020.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2021.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2021.txt new file mode 100644 index 0000000..acefdd5 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2021.txt @@ -0,0 +1,25003 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: HDRP2021 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + + [HideInInspector]_RenderQueueType("Float", Float) = 1 + [HideInInspector][ToggleUI]_AddPrecomputedVelocity("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_DepthOffsetEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentWritingMotionVec("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaCutoffEnable("Boolean", Float) = 0 + [HideInInspector]_TransparentSortPriority("_TransparentSortPriority", Float) = 0 + [HideInInspector][ToggleUI]_UseShadowThreshold("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPrepassEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPostpassEnable("Boolean", Float) = 0 + [HideInInspector]_SurfaceType("Float", Float) = 0 + [HideInInspector]_BlendMode("Float", Float) = 0 + [HideInInspector]_SrcBlend("Float", Float) = 1 + [HideInInspector]_DstBlend("Float", Float) = 0 + [HideInInspector]_AlphaSrcBlend("Float", Float) = 1 + [HideInInspector]_AlphaDstBlend("Float", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMask("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMaskInspectorValue("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ZWrite("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_TransparentZWrite("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableFogOnTransparent("Boolean", Float) = 1 + [HideInInspector]_ZTestDepthEqualForOpaque("Float", Int) = 4 + [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestTransparent("Float", Float) = 4 + [HideInInspector][ToggleUI]_TransparentBackfaceEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_RequireSplitLighting("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ReceivesSSR("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_ReceivesSSRTransparent("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableBlendModePreserveSpecularLighting("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_SupportDecals("Boolean", Float) = 1 + [HideInInspector]_StencilRef("Float", Int) = 0 + [HideInInspector]_StencilWriteMask("Float", Int) = 6 + [HideInInspector]_StencilRefDepth("Float", Int) = 8 + [HideInInspector]_StencilWriteMaskDepth("Float", Int) = 8 + [HideInInspector]_StencilRefMV("Float", Int) = 40 + [HideInInspector]_StencilWriteMaskMV("Float", Int) = 40 + [HideInInspector]_StencilRefDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskGBuffer("Float", Int) = 14 + [HideInInspector]_StencilRefGBuffer("Float", Int) = 10 + [HideInInspector]_ZTestGBuffer("Float", Int) = 4 + [HideInInspector][ToggleUI]_RayTracing("Boolean", Float) = 0 + [HideInInspector][Enum(None, 0, Box, 1, Sphere, 2, Thin, 3)]_RefractionModel("Float", Float) = 0 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" "Queue" = "Geometry+225" } + + + Pass + { + // based on HDLitPass.template + Name "Forward" + Tags { "LightMode" = "Forward" } + + + + Stencil + { + WriteMask [_StencilWriteMask] + Ref [_StencilRef] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + ColorMask [_ColorMaskTransparentVel] 1 + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile_raytracing PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_raytracing _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH + #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON + #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST + + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_FORWARD + #define SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING + #define HAS_LIGHTLOOP + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #ifdef UNITY_VIRTUAL_TEXTURING + #define VT_BUFFER_TARGET SV_Target1 + #define EXTRA_BUFFER_TARGET SV_Target2 + #else + #define EXTRA_BUFFER_TARGET SV_Target1 + #endif + + + + + void Frag(VertexToPixel v2p, + #ifdef OUTPUT_SPLIT_LIGHTING + out float4 outColor : SV_Target0, // outSpecularLighting + #ifdef UNITY_VIRTUAL_TEXTURING + out float4 outVTFeedback : VT_BUFFER_TARGET, + #endif + out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET, + OUTPUT_SSSBUFFER(outSSSBuffer) + #else + out float4 outColor : SV_Target0 + #ifdef UNITY_VIRTUAL_TEXTURING + ,out float4 outVTFeedback : VT_BUFFER_TARGET + #endif + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + , out float4 outMotionVec : EXTRA_BUFFER_TARGET + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + #endif // OUTPUT_SPLIT_LIGHTING + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + // Init outMotionVector here to solve compiler warning (potentially unitialized variable) + // It is init to the value of forceNoMotion (with 2.0) + outMotionVec = float4(2.0, 0.0, 0.0, 0.0); + #endif + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer. + input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy; + + uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + + PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); + + outColor = float4(0.0, 0.0, 0.0, 0.0); + + // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. + + #ifdef DEBUG_DISPLAY + // Init in debug display mode to quiet warning + #ifdef OUTPUT_SPLIT_LIGHTING + outDiffuseLighting = 0; + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #endif + + + + // Same code in ShaderPassForwardUnlit.shader + // Reminder: _DebugViewMaterialArray[i] + // i==0 -> the size used in the buffer + // i>0 -> the index used (0 value means nothing) + // The index stored in this buffer could either be + // - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported) + // - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty) + bool viewMaterial = false; + int bufferSize = _DebugViewMaterialArray[0].x; + if (bufferSize != 0) + { + bool needLinearToSRGB = false; + float3 result = float3(1.0, 0.0, 1.0); + + // Loop through the whole buffer + // Works because GetSurfaceDataDebug will do nothing if the index is not a known one + for (int index = 1; index <= bufferSize; index++) + { + int indexMaterialProperty = _DebugViewMaterialArray[index].x; + + // skip if not really in use + if (indexMaterialProperty != 0) + { + viewMaterial = true; + + GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB); + GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB); + GetBuiltinDataDebug(indexMaterialProperty, builtinData, posInput, result, needLinearToSRGB); + GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB); + GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB); + } + } + + // TEMP! + // For now, the final blit in the backbuffer performs an sRGB write + // So in the meantime we apply the inverse transform to linear data to compensate. + if (!needLinearToSRGB) + result = SRGBToLinear(max(0, result)); + + outColor = float4(result, 1.0); + } + + if (!viewMaterial) + { + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR) + { + float3 result = float3(0.0, 0.0, 0.0); + + GetPBRValidatorDebug(surfaceData, result); + + outColor = float4(result, 1.0f); + } + else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) + { + float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A); + outColor = result; + } + else + #endif + { + #ifdef _SURFACE_TYPE_TRANSPARENT + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; + #else + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; + #endif + + LightLoopOutput lightLoopOutput; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput); + + float3 diffuseLighting = lightLoopOutput.diffuseLighting; + float3 specularLighting = lightLoopOutput.specularLighting; + + diffuseLighting *= GetCurrentExposureMultiplier(); + specularLighting *= GetCurrentExposureMultiplier(); + + #ifdef OUTPUT_SPLIT_LIGHTING + if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) + { + outColor = float4(specularLighting, 1.0); + outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); + } + else + { + outColor = float4(diffuseLighting + specularLighting, 1.0); + outDiffuseLighting = 0; + } + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #else + outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); + outColor = EvaluateAtmosphericScattering(posInput, V, outColor); + #endif + + ChainFinalColorForward(l, d, outColor); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0); + // outMotionVec is already initialize at the value of forceNoMotion (see above) + if (!forceNoMotion) + { + float2 motionVec = CalculateMotionVector(v2p.motionVectorCS, v2p.previousPositionCS); + EncodeMotionVector(motionVec * 0.5, outMotionVec); + outMotionVec.zw = 1.0; + } + #endif + } + + #ifdef DEBUG_DISPLAY + } + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + outVTFeedback = builtinData.vtPackedFeedback; + #endif + } + + ENDHLSL + } + Pass + { + // based on HDLitPass.template + Name "GBuffer" + Tags { "LightMode" = "GBuffer" } + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZTest [_ZTestGBuffer] + Stencil + { + WriteMask [_StencilWriteMaskGBuffer] + Ref [_StencilRefGBuffer] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + Cull [_CullingOption] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + + #pragma multi_compile _ LIGHT_LAYERS + #pragma multi_compile_raytracing _ LIGHT_LAYERS + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile_raytracing PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_raytracing _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_GBUFFER + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + void Frag( VertexToPixel v2f, + OUTPUT_GBUFFER(outGBuffer) + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZWrite On + ColorMask 0 + ZClip [_ZClip] + + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_SHADOWS + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + #endif + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + + + } + + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "DepthOnly" + Tags { "LightMode" = "DepthOnly" } + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + + ZWrite On + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskDepth] + Ref [_StencilRefDepth] + Comp Always + Pass Replace + } + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH + #define RAYTRACING_SHADER_GRAPH_HIGH + #define _PASSDEPTH 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2p + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // to prevent stripping + surfaceData.normalWS *= saturate(l.Albedo.r + 9999); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + } + + + + ENDHLSL + } + + + + Pass + { + // based on HDLitPass.template + Name "META" + Tags { "LightMode" = "META" } + + Cull Off + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + #define _PASSMETA 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + float4 Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // no debug apply during light transport pass + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); + + // This shader is call two times. Once for getting emissiveColor, the other time to get diffuseColor + // We use unity_MetaFragmentControl to make the distinction. + float4 res = float4(0.0, 0.0, 0.0, 1.0); + + if (unity_MetaFragmentControl.x) + { + // Apply diffuseColor Boost from LightmapSettings. + // put abs here to silent a warning, no cost, no impact as color is assume to be positive. + res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); + } + + if (unity_MetaFragmentControl.y) + { + // emissive use HDR format + res.rgb = lightTransportData.emissiveColor; + } + + return res; + } + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + Cull Off + ColorMask 0 + + + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define SCENESELECTIONPASS + #define _PASSSCENESELECT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + void Frag( VertexToPixel IN + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + FragInputs input = BuildFragInputs(IN); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(IN, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + Pass + { + Name "ScenePickingPass" + Tags + { + "LightMode" = "Picking" + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENEPICKINGPASS + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + + } + + ENDHLSL + } + + Pass + { + Name "MotionVectors" + Tags + { + "LightMode" = "MotionVectors" + } + + // Render State + Cull Back + ZWrite On + Stencil + { + WriteMask [_StencilWriteMaskMV] + Ref [_StencilRefMV] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + + #pragma multi_compile _ WRITE_MSAA_DEPTH + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ WRITE_NORMAL_BUFFER + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ WRITE_DECAL_BUFFER + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_MOTION_VECTORS + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define VARYINGS_NEED_PASS + #define _PASSMOTIONVECTOR 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#if defined(WRITE_DECAL_BUFFER) && defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target3 +#elif defined(WRITE_DECAL_BUFFER) || defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target2 +#else +#define SV_TARGET_NORMAL SV_Target1 +#endif + +// Caution: Motion vector pass is different from Depth prepass, it render normal buffer last instead of decal buffer last +// and thus, we force a write of 0 if _DISABLE_DECALS so we always write in the decal buffer. +// This is required as we can't make distinction between deferred (write normal buffer) and forward (write normal buffer) +// in the context of the motion vector pass. The cost is acceptable as it is only do object with motion vector (usualy skin object) +// that most of the time use Forward Material (so are already writing motion vector data). +// So note that here unlike for depth prepass we don't check && !defined(_DISABLE_DECALS) +void Frag( VertexToPixel v2f + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + , out float4 outMotionVector : SV_Target1 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target2 + #endif + #else + // When no MSAA, the motion vector is always the first buffer + , out float4 outMotionVector : SV_Target0 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target1 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_TARGET_NORMAL + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + + FragInputs input = BuildFragInputs(v2f); + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + #ifdef _DEPTHOFFSET_ON + v2f.motionVectorCS.w += builtinData.depthOffset; + v2f.previousPositionCS.w += builtinData.depthOffset; + #endif + + // TODO: How to allow overriden motion vector from GetSurfaceAndBuiltinData ? + float2 motionVector = CalculateMotionVector(v2f.motionVectorCS, v2f.previousPositionCS); + + // Convert from Clip space (-1..1) to NDC 0..1 space. + // Note it doesn't mean we don't have negative value, we store negative or positive offset in NDC space. + // Note: ((positionCS * 0.5 + 0.5) - (v2f.previousPositionCS * 0.5 + 0.5)) = (motionVector * 0.5) + EncodeMotionVector(motionVector * 0.5, outMotionVector); + + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + // Setting the motionVector to a value more than 2 set as a flag for "force no motion". This is valid because, given that the velocities are in NDC, + // a value of >1 can never happen naturally, unless explicitely set. + if (forceNoMotion) + outMotionVector = float4(2.0, 0.0, 0.0, 0.0); + + // Depth and Alpha to coverage + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif + #endif + + // Normal Buffer Processing + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) + DecalPrepassData decalPrepassData; + // Force a write in decal buffer even if decal is disab. This is a neutral value which have no impact for later pass + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + #endif + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + outDecalBuffer.w = (GetMeshRenderingLightLayer() & 0x000000FF) / 255.0; + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + + Pass + { + Name "FullScreenDebug" + Tags + { + "LightMode" = "FullScreenDebug" + } + + // Render State + Cull Back + ZTest LEqual + ZWrite Off + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_FULL_SCREEN_DEBUG + #define _PASSFULLSCREENDEBUG 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB +#if UNITY_VERSION >= UNITY_2021_3_31 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + + + // compute world space normal + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs.tangentToWorld[2], alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + //posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #if defined(UNITY_VIRTUAL_TEXTURING) + builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#define DEBUG_DISPLAY +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/FullScreenDebug.hlsl" + + #if !defined(_DEPTHOFFSET_ON) + [earlydepthstencil] // quad overshading debug mode writes to UAV + #endif + void Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz); + + #ifdef PLATFORM_SUPPORTS_PRIMITIVE_ID_IN_PIXEL_SHADER + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_QUAD_OVERDRAW) + { + IncrementQuadOverdrawCounter(posInput.positionSS.xy, input.primitiveID); + } + #endif + } + + ENDHLSL + } + + + + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2021.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2021.txt.meta new file mode 100644 index 0000000..93467f3 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2021.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 5545a9e4fbadc354c82bb73fb11b0af7 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2021.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2022.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2022.txt new file mode 100644 index 0000000..5b8610e --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2022.txt @@ -0,0 +1,25832 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: HDRP2022 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + + [HideInInspector]_RenderQueueType("Float", Float) = 1 + [HideInInspector][ToggleUI]_AddPrecomputedVelocity("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_DepthOffsetEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentWritingMotionVec("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaCutoffEnable("Boolean", Float) = 0 + [HideInInspector]_TransparentSortPriority("_TransparentSortPriority", Float) = 0 + [HideInInspector][ToggleUI]_UseShadowThreshold("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPrepassEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPostpassEnable("Boolean", Float) = 0 + [HideInInspector]_SurfaceType("Float", Float) = 0 + [HideInInspector]_BlendMode("Float", Float) = 0 + [HideInInspector]_SrcBlend("Float", Float) = 1 + [HideInInspector]_DstBlend("Float", Float) = 0 + [HideInInspector]_AlphaSrcBlend("Float", Float) = 1 + [HideInInspector]_AlphaDstBlend("Float", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMask("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMaskInspectorValue("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ZWrite("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_TransparentZWrite("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableFogOnTransparent("Boolean", Float) = 1 + [HideInInspector]_ZTestDepthEqualForOpaque("Float", Int) = 4 + [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestTransparent("Float", Float) = 4 + [HideInInspector][ToggleUI]_TransparentBackfaceEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_RequireSplitLighting("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ReceivesSSR("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_ReceivesSSRTransparent("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableBlendModePreserveSpecularLighting("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_SupportDecals("Boolean", Float) = 1 + [HideInInspector]_StencilRef("Float", Int) = 0 + [HideInInspector]_StencilWriteMask("Float", Int) = 6 + [HideInInspector]_StencilRefDepth("Float", Int) = 8 + [HideInInspector]_StencilWriteMaskDepth("Float", Int) = 8 + [HideInInspector]_StencilRefMV("Float", Int) = 40 + [HideInInspector]_StencilWriteMaskMV("Float", Int) = 40 + [HideInInspector]_StencilRefDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskGBuffer("Float", Int) = 14 + [HideInInspector]_StencilRefGBuffer("Float", Int) = 10 + [HideInInspector]_ZTestGBuffer("Float", Int) = 4 + [HideInInspector][ToggleUI]_RayTracing("Boolean", Float) = 0 + [HideInInspector][Enum(None, 0, Box, 1, Sphere, 2, Thin, 3)]_RefractionModel("Float", Float) = 0 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" "Queue" = "Geometry+225" } + + + Pass + { + // based on HDLitPass.template + Name "Forward" + Tags { "LightMode" = "Forward" } + + + + Stencil + { + WriteMask [_StencilWriteMask] + Ref [_StencilRef] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + ColorMask [_ColorMaskTransparentVel] 1 + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile_raytracing PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_raytracing _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON + #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST + #pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH + #pragma multi_compile _ LOD_FADE_CROSSFADE + + + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_FORWARD + #define SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING + #define HAS_LIGHTLOOP + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #ifdef UNITY_VIRTUAL_TEXTURING + #define VT_BUFFER_TARGET SV_Target1 + #define EXTRA_BUFFER_TARGET SV_Target2 + #else + #define EXTRA_BUFFER_TARGET SV_Target1 + #endif + + + + + void Frag(VertexToPixel v2p, + #ifdef OUTPUT_SPLIT_LIGHTING + out float4 outColor : SV_Target0, // outSpecularLighting + #ifdef UNITY_VIRTUAL_TEXTURING + out float4 outVTFeedback : VT_BUFFER_TARGET, + #endif + out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET, + OUTPUT_SSSBUFFER(outSSSBuffer) + #else + out float4 outColor : SV_Target0 + #ifdef UNITY_VIRTUAL_TEXTURING + ,out float4 outVTFeedback : VT_BUFFER_TARGET + #endif + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + , out float4 outMotionVec : EXTRA_BUFFER_TARGET + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + #endif // OUTPUT_SPLIT_LIGHTING + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + // Init outMotionVector here to solve compiler warning (potentially unitialized variable) + // It is init to the value of forceNoMotion (with 2.0) + outMotionVec = float4(2.0, 0.0, 0.0, 0.0); + #endif + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer. + input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy; + + uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + + PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); + + outColor = float4(0.0, 0.0, 0.0, 0.0); + + // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. + + #ifdef DEBUG_DISPLAY + // Init in debug display mode to quiet warning + #ifdef OUTPUT_SPLIT_LIGHTING + outDiffuseLighting = 0; + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #endif + + + + // Same code in ShaderPassForwardUnlit.shader + // Reminder: _DebugViewMaterialArray[i] + // i==0 -> the size used in the buffer + // i>0 -> the index used (0 value means nothing) + // The index stored in this buffer could either be + // - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported) + // - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty) + bool viewMaterial = false; + int bufferSize = _DebugViewMaterialArray[0].x; + if (bufferSize != 0) + { + bool needLinearToSRGB = false; + float3 result = float3(1.0, 0.0, 1.0); + + // Loop through the whole buffer + // Works because GetSurfaceDataDebug will do nothing if the index is not a known one + for (int index = 1; index <= bufferSize; index++) + { + int indexMaterialProperty = _DebugViewMaterialArray[index].x; + + // skip if not really in use + if (indexMaterialProperty != 0) + { + viewMaterial = true; + + GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB); + GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB); + GetBuiltinDataDebug(indexMaterialProperty, builtinData, posInput, result, needLinearToSRGB); + GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB); + GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB); + } + } + + // TEMP! + // For now, the final blit in the backbuffer performs an sRGB write + // So in the meantime we apply the inverse transform to linear data to compensate. + if (!needLinearToSRGB) + result = SRGBToLinear(max(0, result)); + + outColor = float4(result, 1.0); + } + + if (!viewMaterial) + { + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR) + { + float3 result = float3(0.0, 0.0, 0.0); + + GetPBRValidatorDebug(surfaceData, result); + + outColor = float4(result, 1.0f); + } + else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) + { + float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A); + outColor = result; + } + else + #endif + { + #ifdef _SURFACE_TYPE_TRANSPARENT + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; + #else + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; + #endif + + LightLoopOutput lightLoopOutput; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput); + + float3 diffuseLighting = lightLoopOutput.diffuseLighting; + float3 specularLighting = lightLoopOutput.specularLighting; + + diffuseLighting *= GetCurrentExposureMultiplier(); + specularLighting *= GetCurrentExposureMultiplier(); + + #ifdef OUTPUT_SPLIT_LIGHTING + if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) + { + outColor = float4(specularLighting, 1.0); + outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); + } + else + { + outColor = float4(diffuseLighting + specularLighting, 1.0); + outDiffuseLighting = 0; + } + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #else + outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); + outColor = EvaluateAtmosphericScattering(posInput, V, outColor); + #endif + + ChainFinalColorForward(l, d, outColor); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0); + // outMotionVec is already initialize at the value of forceNoMotion (see above) + if (!forceNoMotion) + { + float2 motionVec = CalculateMotionVector(v2p.motionVectorCS, v2p.previousPositionCS); + EncodeMotionVector(motionVec * 0.5, outMotionVec); + outMotionVec.zw = 1.0; + } + #endif + } + + #ifdef DEBUG_DISPLAY + } + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + outVTFeedback = builtinData.vtPackedFeedback; + #endif + } + + ENDHLSL + } + Pass + { + // based on HDLitPass.template + Name "GBuffer" + Tags { "LightMode" = "GBuffer" } + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZTest [_ZTestGBuffer] + ColorMask [_LightLayersMaskBuffer4] 4 + ColorMask [_LightLayersMaskBuffer5] 5 + Stencil + { + WriteMask [_StencilWriteMaskGBuffer] + Ref [_StencilRefGBuffer] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + ColorMask [_LightLayersMaskBuffer4] 4 + ColorMask [_LightLayersMaskBuffer5] 5 + + Cull [_CullingOption] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma target 4.5 + + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + #pragma multi_compile _ LIGHT_LAYERS + //#pragma multi_compile_raytracing _ LIGHT_LAYERS + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_GBUFFER + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + void Frag( VertexToPixel v2f, + OUTPUT_GBUFFER(outGBuffer) + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZWrite On + ColorMask 0 + ZClip [_ZClip] + + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_SHADOWS + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + #endif + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + + + } + + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "DepthOnly" + Tags { "LightMode" = "DepthOnly" } + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + + ZWrite On + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskDepth] + Ref [_StencilRefDepth] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + AlphaToMask [_AlphaCutoffEnable] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH + #define _PASSDEPTH 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2p + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : DEPTH_OFFSET_SEMANTIC + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // to prevent stripping + surfaceData.normalWS *= saturate(l.Albedo.r + 9999); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = unity_SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + } + + + + ENDHLSL + } + + + + Pass + { + // based on HDLitPass.template + Name "META" + Tags { "LightMode" = "META" } + + Cull Off + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + #define _PASSMETA 1 + #pragma multi_compile _ LOD_FADE_CROSSFADE + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + float4 Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // no debug apply during light transport pass + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); + + // This shader is call two times. Once for getting emissiveColor, the other time to get diffuseColor + // We use unity_MetaFragmentControl to make the distinction. + float4 res = float4(0.0, 0.0, 0.0, 1.0); + + if (unity_MetaFragmentControl.x) + { + // Apply diffuseColor Boost from LightmapSettings. + // put abs here to silent a warning, no cost, no impact as color is assume to be positive. + res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); + } + + if (unity_MetaFragmentControl.y) + { + // emissive use HDR format + res.rgb = lightTransportData.emissiveColor; + } + + return res; + } + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + Cull Off + ColorMask 0 + + + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define SCENESELECTIONPASS + #define _PASSSCENESELECT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + void Frag( VertexToPixel IN + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + FragInputs input = BuildFragInputs(IN); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(IN, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + Pass + { + Name "ScenePickingPass" + Tags + { + "LightMode" = "Picking" + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENEPICKINGPASS + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + DecalPrepassData decalPrepassData; + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + + } + + ENDHLSL + } + + Pass + { + Name "MotionVectors" + Tags + { + "LightMode" = "MotionVectors" + } + + // Render State + Cull Back + ZWrite On + Stencil + { + WriteMask [_StencilWriteMaskMV] + Ref [_StencilRefMV] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma multi_compile _ WRITE_MSAA_DEPTH + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ WRITE_NORMAL_BUFFER + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ WRITE_DECAL_BUFFER + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_MOTION_VECTORS + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define VARYINGS_NEED_PASS + #define _PASSMOTIONVECTOR 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#if defined(WRITE_DECAL_BUFFER) && defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target3 +#elif defined(WRITE_DECAL_BUFFER) || defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target2 +#else +#define SV_TARGET_NORMAL SV_Target1 +#endif + +// Caution: Motion vector pass is different from Depth prepass, it render normal buffer last instead of decal buffer last +// and thus, we force a write of 0 if _DISABLE_DECALS so we always write in the decal buffer. +// This is required as we can't make distinction between deferred (write normal buffer) and forward (write normal buffer) +// in the context of the motion vector pass. The cost is acceptable as it is only do object with motion vector (usualy skin object) +// that most of the time use Forward Material (so are already writing motion vector data). +// So note that here unlike for depth prepass we don't check && !defined(_DISABLE_DECALS) +void Frag( VertexToPixel v2f + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + , out float4 outMotionVector : SV_Target1 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target2 + #endif + #else + // When no MSAA, the motion vector is always the first buffer + , out float4 outMotionVector : SV_Target0 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target1 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_TARGET_NORMAL + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + + FragInputs input = BuildFragInputs(v2f); + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + #ifdef _DEPTHOFFSET_ON + v2f.motionVectorCS.w += builtinData.depthOffset; + v2f.previousPositionCS.w += builtinData.depthOffset; + #endif + + // TODO: How to allow overriden motion vector from GetSurfaceAndBuiltinData ? + float2 motionVector = CalculateMotionVector(v2f.motionVectorCS, v2f.previousPositionCS); + + // Convert from Clip space (-1..1) to NDC 0..1 space. + // Note it doesn't mean we don't have negative value, we store negative or positive offset in NDC space. + // Note: ((positionCS * 0.5 + 0.5) - (v2f.previousPositionCS * 0.5 + 0.5)) = (motionVector * 0.5) + EncodeMotionVector(motionVector * 0.5, outMotionVector); + + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + // Setting the motionVector to a value more than 2 set as a flag for "force no motion". This is valid because, given that the velocities are in NDC, + // a value of >1 can never happen naturally, unless explicitely set. + if (forceNoMotion) + outMotionVector = float4(2.0, 0.0, 0.0, 0.0); + + // Depth and Alpha to coverage + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif + #endif + + // Normal Buffer Processing + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) + DecalPrepassData decalPrepassData; + // Force a write in decal buffer even if decal is disab. This is a neutral value which have no impact for later pass + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer(); + #endif + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + outDecalBuffer.w = (GetMeshRenderingLightLayer() & 0x000000FF) / 255.0; + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + + Pass + { + Name "FullScreenDebug" + Tags + { + "LightMode" = "FullScreenDebug" + } + + // Render State + Cull Back + ZTest LEqual + ZWrite Off + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ LOD_FADE_CROSSFADE + + + #define SHADERPASS SHADERPASS_FULL_SCREEN_DEBUG + #define _PASSFULLSCREENDEBUG 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" + +#if UNITY_VERSION >= 202239 + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition +#else + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphHeader.hlsl" +#endif + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#define DEBUG_DISPLAY +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/FullScreenDebug.hlsl" + + #if !defined(_DEPTHOFFSET_ON) + [earlydepthstencil] // quad overshading debug mode writes to UAV + #endif + void Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz); + + #ifdef PLATFORM_SUPPORTS_PRIMITIVE_ID_IN_PIXEL_SHADER + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_QUAD_OVERDRAW) + { + IncrementQuadOverdrawCounter(posInput.positionSS.xy, input.primitiveID); + } + #endif + } + + ENDHLSL + } + + + + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2022.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2022.txt.meta new file mode 100644 index 0000000..e89900a --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2022.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: f92b26827dd1dcc45b0edccd67279b1d +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2022.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2023.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2023.txt new file mode 100644 index 0000000..85bcd12 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2023.txt @@ -0,0 +1,25883 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: HDRP2023 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + + [HideInInspector]_RenderQueueType("Float", Float) = 1 + [HideInInspector][ToggleUI]_AddPrecomputedVelocity("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_DepthOffsetEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentWritingMotionVec("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaCutoffEnable("Boolean", Float) = 0 + [HideInInspector]_TransparentSortPriority("_TransparentSortPriority", Float) = 0 + [HideInInspector][ToggleUI]_UseShadowThreshold("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPrepassEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_TransparentDepthPostpassEnable("Boolean", Float) = 0 + [HideInInspector]_SurfaceType("Float", Float) = 0 + [HideInInspector]_BlendMode("Float", Float) = 0 + [HideInInspector]_SrcBlend("Float", Float) = 1 + [HideInInspector]_DstBlend("Float", Float) = 0 + [HideInInspector]_AlphaSrcBlend("Float", Float) = 1 + [HideInInspector]_AlphaDstBlend("Float", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMask("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_AlphaToMaskInspectorValue("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ZWrite("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_TransparentZWrite("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableFogOnTransparent("Boolean", Float) = 1 + [HideInInspector]_ZTestDepthEqualForOpaque("Float", Int) = 4 + [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)]_ZTestTransparent("Float", Float) = 4 + [HideInInspector][ToggleUI]_TransparentBackfaceEnable("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_RequireSplitLighting("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_ReceivesSSR("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_ReceivesSSRTransparent("Boolean", Float) = 0 + [HideInInspector][ToggleUI]_EnableBlendModePreserveSpecularLighting("Boolean", Float) = 1 + [HideInInspector][ToggleUI]_SupportDecals("Boolean", Float) = 1 + [HideInInspector]_StencilRef("Float", Int) = 0 + [HideInInspector]_StencilWriteMask("Float", Int) = 6 + [HideInInspector]_StencilRefDepth("Float", Int) = 8 + [HideInInspector]_StencilWriteMaskDepth("Float", Int) = 8 + [HideInInspector]_StencilRefMV("Float", Int) = 40 + [HideInInspector]_StencilWriteMaskMV("Float", Int) = 40 + [HideInInspector]_StencilRefDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskDistortionVec("Float", Int) = 4 + [HideInInspector]_StencilWriteMaskGBuffer("Float", Int) = 14 + [HideInInspector]_StencilRefGBuffer("Float", Int) = 10 + [HideInInspector]_ZTestGBuffer("Float", Int) = 4 + [HideInInspector][ToggleUI]_RayTracing("Boolean", Float) = 0 + [HideInInspector][Enum(None, 0, Box, 1, Sphere, 2, Thin, 3)]_RefractionModel("Float", Float) = 0 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" "Queue" = "Geometry+225" } + + + Pass + { + // based on HDLitPass.template + Name "Forward" + Tags { "LightMode" = "Forward" } + + + + Stencil + { + WriteMask [_StencilWriteMask] + Ref [_StencilRef] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + ColorMask [_ColorMaskTransparentVel] 1 + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH + #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON + #pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST + #pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH + #pragma multi_compile _ LOD_FADE_CROSSFADE + #pragma multi_compile _ USE_LEGACY_LIGHTMAPS + + + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_FORWARD + #define SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING + #define HAS_LIGHTLOOP + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #ifdef UNITY_VIRTUAL_TEXTURING + #define VT_BUFFER_TARGET SV_Target1 + #define EXTRA_BUFFER_TARGET SV_Target2 + #else + #define EXTRA_BUFFER_TARGET SV_Target1 + #endif + + + + + void Frag(VertexToPixel v2p, + #ifdef OUTPUT_SPLIT_LIGHTING + out float4 outColor : SV_Target0, // outSpecularLighting + #ifdef UNITY_VIRTUAL_TEXTURING + out float4 outVTFeedback : VT_BUFFER_TARGET, + #endif + out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET, + OUTPUT_SSSBUFFER(outSSSBuffer) + #else + out float4 outColor : SV_Target0 + #ifdef UNITY_VIRTUAL_TEXTURING + ,out float4 outVTFeedback : VT_BUFFER_TARGET + #endif + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + , out float4 outMotionVec : EXTRA_BUFFER_TARGET + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + #endif // OUTPUT_SPLIT_LIGHTING + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + // Init outMotionVector here to solve compiler warning (potentially unitialized variable) + // It is init to the value of forceNoMotion (with 2.0) + outMotionVec = float4(2.0, 0.0, 0.0, 0.0); + #endif + + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer. + input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy; + + uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + + PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); + + outColor = float4(0.0, 0.0, 0.0, 0.0); + + // We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4. + + #ifdef DEBUG_DISPLAY + // Init in debug display mode to quiet warning + #ifdef OUTPUT_SPLIT_LIGHTING + outDiffuseLighting = 0; + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #endif + + + + // Same code in ShaderPassForwardUnlit.shader + // Reminder: _DebugViewMaterialArray[i] + // i==0 -> the size used in the buffer + // i>0 -> the index used (0 value means nothing) + // The index stored in this buffer could either be + // - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported) + // - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty) + bool viewMaterial = false; + int bufferSize = _DebugViewMaterialArray[0].x; + if (bufferSize != 0) + { + bool needLinearToSRGB = false; + float3 result = float3(1.0, 0.0, 1.0); + + // Loop through the whole buffer + // Works because GetSurfaceDataDebug will do nothing if the index is not a known one + for (int index = 1; index <= bufferSize; index++) + { + int indexMaterialProperty = _DebugViewMaterialArray[index].x; + + // skip if not really in use + if (indexMaterialProperty != 0) + { + viewMaterial = true; + + GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB); + GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB); + GetBuiltinDataDebug(indexMaterialProperty, builtinData, posInput, result, needLinearToSRGB); + GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB); + GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB); + } + } + + // TEMP! + // For now, the final blit in the backbuffer performs an sRGB write + // So in the meantime we apply the inverse transform to linear data to compensate. + if (!needLinearToSRGB) + result = SRGBToLinear(max(0, result)); + + outColor = float4(result, 1.0); + } + + if (!viewMaterial) + { + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR) + { + float3 result = float3(0.0, 0.0, 0.0); + + GetPBRValidatorDebug(surfaceData, result); + + outColor = float4(result, 1.0f); + } + else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) + { + float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A); + outColor = result; + } + else + #endif + { + #ifdef _SURFACE_TYPE_TRANSPARENT + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT; + #else + uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE; + #endif + + LightLoopOutput lightLoopOutput; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput); + + float3 diffuseLighting = lightLoopOutput.diffuseLighting; + float3 specularLighting = lightLoopOutput.specularLighting; + + diffuseLighting *= GetCurrentExposureMultiplier(); + specularLighting *= GetCurrentExposureMultiplier(); + + #ifdef OUTPUT_SPLIT_LIGHTING + if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData)) + { + outColor = float4(specularLighting, 1.0); + outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0); + } + else + { + outColor = float4(diffuseLighting + specularLighting, 1.0); + outDiffuseLighting = 0; + } + ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer); + #else + outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity); + outColor = EvaluateAtmosphericScattering(posInput, V, outColor); + #endif + + ChainFinalColorForward(l, d, outColor); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0); + // outMotionVec is already initialize at the value of forceNoMotion (see above) + if (!forceNoMotion) + { + float2 motionVec = CalculateMotionVector(v2p.motionVectorCS, v2p.previousPositionCS); + EncodeMotionVector(motionVec * 0.5, outMotionVec); + outMotionVec.zw = 1.0; + } + #endif + } + + #ifdef DEBUG_DISPLAY + } + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + outVTFeedback = builtinData.vtPackedFeedback; + #endif + } + + ENDHLSL + } + Pass + { + // based on HDLitPass.template + Name "GBuffer" + Tags { "LightMode" = "GBuffer" } + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZTest [_ZTestGBuffer] + Stencil + { + WriteMask [_StencilWriteMaskGBuffer] + Ref [_StencilRefGBuffer] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + Cull [_CullingOption] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma target 4.5 + + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ LOD_FADE_CROSSFADE + #pragma multi_compile_fragment _ RENDERING_LAYERS + //#pragma multi_compile_raytracing _ LIGHT_LAYERS + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ DEBUG_DISPLAY + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2 + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK + #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT + #pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT + #pragma multi_compile _ USE_LEGACY_LIGHTMAPS + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_GBUFFER + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + void Frag( VertexToPixel v2f, + OUTPUT_GBUFFER(outGBuffer) + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + } + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + + + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + ZWrite On + ColorMask 0 + ZClip [_ZClip] + + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + //#pragma multi_compile_local _ _ALPHATEST_ON + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_SHADOWS + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + //------------------------------------------------------------------------------------- + // Defines + //------------------------------------------------------------------------------------- + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + #endif + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER) + DecalPrepassData decalPrepassData; + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + #endif + decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + + + } + + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "DepthOnly" + Tags { "LightMode" = "DepthOnly" } + + //------------------------------------------------------------------------------------- + // Render Modes (Blend, Cull, ZTest, Stencil, etc) + //------------------------------------------------------------------------------------- + + Cull Back + + + ZWrite On + + + // Stencil setup + Stencil + { + WriteMask [_StencilWriteMaskDepth] + Ref [_StencilRefDepth] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + AlphaToMask [_AlphaCutoffEnable] + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + //#pragma enable_d3d11_debug_symbols + + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH + #define _PASSDEPTH 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + #if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target2 + #elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH) + #define SV_TARGET_DECAL SV_Target1 + #else + #define SV_TARGET_DECAL SV_Target0 + #endif + + + void Frag( VertexToPixel v2p + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + + #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS) + , out float outputDepth : DEPTH_OFFSET_SEMANTIC + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2p); + FragInputs input = BuildFragInputs(v2p); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2p, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // to prevent stripping + surfaceData.normalWS *= saturate(l.Albedo.r + 9999); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = unity_SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER) + DecalPrepassData decalPrepassData; + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + #endif + decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + } + + + + ENDHLSL + } + + + + Pass + { + // based on HDLitPass.template + Name "META" + Tags { "LightMode" = "META" } + + Cull Off + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma multi_compile_instancing + + //#pragma multi_compile_local _ _ALPHATEST_ON + #pragma multi_compile _ LOD_FADE_CROSSFADE + + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT + #define RAYTRACING_SHADER_GRAPH_HIGH + #define REQUIRE_DEPTH_TEXTURE + #define _PASSMETA 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + float4 Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + // no debug apply during light transport pass + + BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData); + LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData); + + // This shader is call two times. Once for getting emissiveColor, the other time to get diffuseColor + // We use unity_MetaFragmentControl to make the distinction. + float4 res = float4(0.0, 0.0, 0.0, 1.0); + + if (unity_MetaFragmentControl.x) + { + // Apply diffuseColor Boost from LightmapSettings. + // put abs here to silent a warning, no cost, no impact as color is assume to be positive. + res.rgb = clamp(pow(abs(lightTransportData.diffuseColor), saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); + } + + if (unity_MetaFragmentControl.y) + { + // emissive use HDR format + res.rgb = lightTransportData.emissiveColor; + } + + return res; + } + + + + ENDHLSL + } + + Pass + { + // based on HDLitPass.template + Name "SceneSelectionPass" + Tags { "LightMode" = "SceneSelectionPass" } + + Cull Off + ColorMask 0 + + + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + //------------------------------------------------------------------------------------- + // Variant Definitions (active field translations to HDRP defines) + //------------------------------------------------------------------------------------- + // #define _MATERIAL_FEATURE_SUBSURFACE_SCATTERING 1 + // #define _MATERIAL_FEATURE_TRANSMISSION 1 + // #define _MATERIAL_FEATURE_ANISOTROPY 1 + // #define _MATERIAL_FEATURE_IRIDESCENCE 1 + // #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + #define _ENABLE_FOG_ON_TRANSPARENT 1 + // #define _AMBIENT_OCCLUSION 1 + // #define _SPECULAR_OCCLUSION_FROM_AO 1 + // #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 + // #define _SPECULAR_OCCLUSION_CUSTOM 1 + // #define _ENERGY_CONSERVING_SPECULAR 1 + // #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 + // #define _HAS_REFRACTION 1 + // #define _REFRACTION_PLANE 1 + // #define _REFRACTION_SPHERE 1 + // #define _DISABLE_DECALS 1 + // #define _DISABLE_SSR 1 + // #define _ADD_PRECOMPUTED_VELOCITY + // #define _WRITE_TRANSPARENT_MOTION_VECTOR 1 + // #define _DEPTHOFFSET_ON 1 + // #define _BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1 + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define SCENESELECTIONPASS + #define _PASSSCENESELECT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + + + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + + void Frag( VertexToPixel IN + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #ifdef WRITE_MSAA_DEPTH + , out float1 depthColor : SV_Target1 + #endif + #elif defined(WRITE_MSAA_DEPTH) // When only WRITE_MSAA_DEPTH is define and not WRITE_NORMAL_BUFFER it mean we are Unlit and only need depth, but we still have normal buffer binded + , out float4 outNormalBuffer : SV_Target0 + , out float1 depthColor : SV_Target1 + #elif defined(SCENESELECTIONPASS) + , out float4 outColor : SV_Target0 + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + FragInputs input = BuildFragInputs(IN); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(IN, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), posInput.positionSS, outNormalBuffer); + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #endif + #elif defined(WRITE_MSAA_DEPTH) // When we are MSAA depth only without normal buffer + // Due to the binding order of these two render targets, we need to have them both declared + outNormalBuffer = float4(0.0, 0.0, 0.0, 1.0); + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + #elif defined(SCENESELECTIONPASS) + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #endif + } + + ENDHLSL + } + + + Pass + { + Name "ScenePickingPass" + Tags + { + "LightMode" = "Picking" + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma editor_sync_compilation + #pragma instancing_options renderinglayer + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ WRITE_DECAL_BUFFER + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #define SHADERPASS SHADERPASS_DEPTH_ONLY + #define SCENEPICKINGPASS + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + void Frag( VertexToPixel v2f + #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS) + , out float4 outColor : SV_Target0 + #else + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #else + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target0 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + , out float4 outDecalBuffer : SV_TARGET_DECAL + #endif + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + // input.positionSS is SV_Position + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + + + #ifdef SCENESELECTIONPASS + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif defined(SCENEPICKINGPASS) + outColor = _SelectionID; + #else + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2p.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif // alphatomask + #endif // msaa_depth + + + #if defined(WRITE_NORMAL_BUFFER) + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER) + DecalPrepassData decalPrepassData; + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + #endif + decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask(); + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + #endif + #endif + + + } + + ENDHLSL + } + + Pass + { + Name "MotionVectors" + Tags + { + "LightMode" = "MotionVectors" + } + + // Render State + Cull Back + ZWrite On + Stencil + { + WriteMask [_StencilWriteMaskMV] + Ref [_StencilRefMV] + CompFront Always + PassFront Replace + CompBack Always + PassBack Replace + } + + + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + #pragma instancing_options renderinglayer + #pragma multi_compile _ LOD_FADE_CROSSFADE + + #pragma multi_compile _ WRITE_MSAA_DEPTH + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + #pragma multi_compile _ WRITE_NORMAL_BUFFER + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + #pragma multi_compile _ WRITE_DECAL_BUFFER + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + + + + #define SHADERPASS SHADERPASS_MOTION_VECTORS + #define RAYTRACING_SHADER_GRAPH_DEFAULT + #define VARYINGS_NEED_PASS + #define _PASSMOTIONVECTOR 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#if defined(WRITE_DECAL_BUFFER) && defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target3 +#elif defined(WRITE_DECAL_BUFFER) || defined(WRITE_MSAA_DEPTH) +#define SV_TARGET_NORMAL SV_Target2 +#else +#define SV_TARGET_NORMAL SV_Target1 +#endif + +// Caution: Motion vector pass is different from Depth prepass, it render normal buffer last instead of decal buffer last +// and thus, we force a write of 0 if _DISABLE_DECALS so we always write in the decal buffer. +// This is required as we can't make distinction between deferred (write normal buffer) and forward (write normal buffer) +// in the context of the motion vector pass. The cost is acceptable as it is only do object with motion vector (usualy skin object) +// that most of the time use Forward Material (so are already writing motion vector data). +// So note that here unlike for depth prepass we don't check && !defined(_DISABLE_DECALS) +void Frag( VertexToPixel v2f + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 depthColor : SV_Target0 + , out float4 outMotionVector : SV_Target1 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target2 + #endif + #else + // When no MSAA, the motion vector is always the first buffer + , out float4 outMotionVector : SV_Target0 + #ifdef WRITE_DECAL_BUFFER + , out float4 outDecalBuffer : SV_Target1 + #endif + #endif + + // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS) + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_TARGET_NORMAL + #endif + + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + + FragInputs input = BuildFragInputs(v2f); + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS); + + float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); + + + SurfaceData surfaceData; + BuiltinData builtinData; + Surface l; + ShaderData d; + GetSurfaceAndBuiltinData(v2f, input, V, posInput, surfaceData, builtinData, l, d + #if NEED_FACING + , facing + #endif + ); + + #ifdef _DEPTHOFFSET_ON + v2f.motionVectorCS.w += builtinData.depthOffset; + v2f.previousPositionCS.w += builtinData.depthOffset; + #endif + + // TODO: How to allow overriden motion vector from GetSurfaceAndBuiltinData ? + float2 motionVector = CalculateMotionVector(v2f.motionVectorCS, v2f.previousPositionCS); + + // Convert from Clip space (-1..1) to NDC 0..1 space. + // Note it doesn't mean we don't have negative value, we store negative or positive offset in NDC space. + // Note: ((positionCS * 0.5 + 0.5) - (v2f.previousPositionCS * 0.5 + 0.5)) = (motionVector * 0.5) + EncodeMotionVector(motionVector * 0.5, outMotionVector); + + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + // Setting the motionVector to a value more than 2 set as a flag for "force no motion". This is valid because, given that the velocities are in NDC, + // a value of >1 can never happen naturally, unless explicitely set. + if (forceNoMotion) + outMotionVector = float4(2.0, 0.0, 0.0, 0.0); + + // Depth and Alpha to coverage + #ifdef WRITE_MSAA_DEPTH + // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer + depthColor = v2f.pos.z; + + #ifdef _ALPHATOMASK_ON + // Alpha channel is used for alpha to coverage + depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold); + #endif + #endif + + // Normal Buffer Processing + #ifdef WRITE_NORMAL_BUFFER + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer); + #endif + + #if defined(WRITE_DECAL_BUFFER) + DecalPrepassData decalPrepassData; + // Force a write in decal buffer even if decal is disab. This is a neutral value which have no impact for later pass + #ifdef _DISABLE_DECALS + ZERO_INITIALIZE(DecalPrepassData, decalPrepassData); + #else + // We don't have the right to access SurfaceData in a shaderpass. + // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway + // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway) + decalPrepassData.geomNormalWS = surfaceData.geomNormalWS; + decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask(); + #endif + EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer); + outDecalBuffer.w = (GetMeshRenderingLayerMask() & 0x000000FF) / 255.0; + #endif + + #ifdef _DEPTHOFFSET_ON + outputDepth = posInput.deviceDepth; + #endif + } + + ENDHLSL + } + + + Pass + { + Name "FullScreenDebug" + Tags + { + "LightMode" = "FullScreenDebug" + } + + // Render State + Cull Back + ZTest LEqual + ZWrite Off + + //------------------------------------------------------------------------------------- + // End Render Modes + //------------------------------------------------------------------------------------- + + HLSLPROGRAM + + #pragma target 4.5 + #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch + + + + //#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT + //#pragma shader_feature_local _BLENDMODE_OFF _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY + //#pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY + //#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC + //#pragma shader_feature_local _ _ENABLE_FOG_ON_TRANSPARENT + //#pragma shader_feature_local _ _DISABLE_DECALS + //#pragma shader_feature_local _ _DISABLE_SSR + //#pragma shader_feature_local _ _DISABLE_SSR_TRANSPARENT + //#pragma shader_feature_local _REFRACTION_OFF _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN + #pragma multi_compile _ LOD_FADE_CROSSFADE + + + #define SHADERPASS SHADERPASS_FULL_SCREEN_DEBUG + #define _PASSFULLSCREENDEBUG 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _HDRP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #pragma vertex Vert + #pragma fragment Frag + + // useful conversion functions to make surface shader code just work + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(tex) TEXTURE2D_ARRAY(tex); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #ifndef SHADER_STAGE_FRAGMENT + #if !defined(SHADOW_ULTRA_LOW) && !defined(SHADOW_LOW) && !defined(SHADOW_MEDIUM) && !defined(SHADOW_HIGH) // ultra low come from volumetricLighting.compute + #define SHADOW_MEDIUM + #endif + #if !defined(AREA_SHADOW_LOW) && !defined(AREA_SHADOW_MEDIUM) && !defined(AREA_SHADOW_HIGH) // low come from volumetricLighting.compute + #define AREA_SHADOW_MEDIUM + #endif + #endif + + + +// HDRP Adapter stuff + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl" // Required by Tessellation.hlsl + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" // Required to be include before we include properties as it define DECLARE_STACK_CB + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl" // Required before including properties as it defines UNITY_TEXTURE_STREAMING_DEBUG_VARS + // Always include Shader Graph version + // Always include last to avoid double macros + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" // Need to be here for Gradient struct definition + + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl" + + + + #ifdef RAYTRACING_SHADER_GRAPH_DEFAULT + #define RAYTRACING_SHADER_GRAPH_HIGH + #endif + + #ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED + #define RAYTRACING_SHADER_GRAPH_LOW + #endif + // end + + + + + // If we use subsurface scattering, enable output split lighting (for forward pass) + #if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define OUTPUT_SPLIT_LIGHTING + #endif + + #define HAVE_RECURSIVE_RENDERING + + #if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS + #if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT) + #define WRITE_NORMAL_BUFFER + #endif + #endif + + #ifndef DEBUG_DISPLAY + // In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI) + // Don't do it with debug display mode as it is possible there is no depth prepass in this case + #if !defined(_SURFACE_TYPE_TRANSPARENT) && defined(_ALPHATEST) + #if SHADERPASS == SHADERPASS_FORWARD + #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST + #elif SHADERPASS == SHADERPASS_GBUFFER + #define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST + #endif + #endif + #endif + + // Define _DEFERRED_CAPABLE_MATERIAL for shader capable to run in deferred pass + #if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT) + #define _DEFERRED_CAPABLE_MATERIAL + #endif + + // Translate transparent motion vector define + #if defined(_TRANSPARENT_WRITES_MOTION_VEC) && defined(_SURFACE_TYPE_TRANSPARENT) + #define _WRITE_TRANSPARENT_MOTION_VECTOR + #endif + + + + + CBUFFER_START(UnityPerMaterial) + float _UseShadowThreshold; + float _BlendMode; + float _EnableBlendModePreserveSpecularLighting; + float _RayTracing; + float _RefractionModel; + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + // -- Property used by ScenePickingPass + #ifdef SCENEPICKINGPASS + float4 _SelectionID; + #endif + + // -- Properties used by SceneSelectionPass + #ifdef SCENESELECTIONPASS + int _ObjectId; + int _PassValue; + #endif + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD15; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + UNITY_VERTEX_INPUT_INSTANCE_ID + #endif // UNITY_ANY_INSTANCING_ENABLED + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + float4 previousPositionCS : TEXCOORD16; // Contain previous transform position (in case of skinning for example) + float4 motionVectorCS : TEXCOORD17; + #endif + + UNITY_VERTEX_OUTPUT_STEREO + }; + + + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + +#if (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) + + // This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency + float unity_OneOverOutputBoost; + float unity_MaxOutputValue; + + CBUFFER_START(UnityMetaPass) + // x = use uv1 as raster position + // y = use uv2 as raster position + bool4 unity_MetaVertexControl; + + // x = return albedo + // y = return normal + bool4 unity_MetaFragmentControl; + CBUFFER_END + + VertexToPixel Vert(VertexData inputMesh) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + UNITY_SETUP_INSTANCE_ID(inputMesh); + UNITY_TRANSFER_INSTANCE_ID(inputMesh, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + // Output UV coordinate in vertex shader + float2 uv = float2(0.0, 0.0); + + if (unity_MetaVertexControl.x) + { + uv = inputMesh.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + } + else if (unity_MetaVertexControl.y) + { + uv = inputMesh.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + } + + // OpenGL right now needs to actually use the incoming vertex position + // so we create a fake dependency on it here that haven't any impact. + output.pos = float4(uv * 2.0 - 1.0, inputMesh.vertex.z > 0 ? 1.0e-4 : 0.0, 1.0); + + output.worldPos = TransformObjectToWorld(inputMesh.vertex.xyz).xyz; + + // Normal is required for triplanar mapping + output.worldNormal = TransformObjectToWorldNormal(inputMesh.normal); + // Not required but assign to silent compiler warning + output.worldTangent = float4(1.0, 0.0, 0.0, 0.0); + + output.texcoord0 = inputMesh.texcoord0; + output.texcoord1 = inputMesh.texcoord1; + output.texcoord2 = inputMesh.texcoord2; + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = inputMesh.texcoord3; + // #endif + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = inputMesh.vertexColor; + // #endif + + return output; + } +#else + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesMatrixDefsHDCamera.hlsl" + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + VertexToPixel Vert(VertexData input) + { + VertexToPixel output; + ZERO_INITIALIZE(VertexToPixel, output); + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = input; + #endif + + ChainModifyVertex(input, output, _Time); + + // This return the camera relative position (if enable) + float3 positionRWS = TransformObjectToWorld(input.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(input.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(input.tangent.xyz), input.tangent.w); + + + output.worldPos = GetAbsolutePositionWS(positionRWS); + output.pos = TransformWorldToHClip(positionRWS); + output.worldNormal = normalWS; + output.worldTangent = tangentWS; + + + output.texcoord0 = input.texcoord0; + output.texcoord1 = input.texcoord1; + output.texcoord2 = input.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + output.texcoord3 = input.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + output.vertexColor = input.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // output.screenPos = ComputeScreenPos(output.pos, _ProjectionParams.x); + // #endif + + #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(output); + #endif + + output.motionVectorCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS.xyz, 1.0)); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + if (forceNoMotion) + { + output.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + } + else + { + bool hasDeformation = unity_MotionVectorsParams.x > 0.0; // Skin or morph target + + float3 effectivePositionOS = (hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz); + #if defined(_ADD_PRECOMPUTED_VELOCITY) + effectivePositionOS -= input.precomputedVelocity; + #endif + + previousMesh.vertex = float4(effectivePositionOS, 1); + VertexToPixel dummy = (VertexToPixel)0; + + + ChainModifyVertex(previousMesh, dummy, _LastTimeParameters); + + // we might need this for skinned objects? + //float3 normalWS = TransformPreviousObjectToWorldNormal(input.normal).xyz; + float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.vertex.xyz); + + #ifdef _WRITE_TRANSPARENT_MOTION_VECTOR + if (_TransparentCameraOnlyMotionVectors > 0) + { + previousPositionRWS = positionRWS.xyz; + } + #endif // _WRITE_TRANSPARENT_MOTION_VECTOR + + output.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0)); + } + #endif // _HDRP && _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + + + return output; + } + + +#endif + + + + + + + + #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" + #endif + + FragInputs BuildFragInputs(VertexToPixel input) + { + UNITY_SETUP_INSTANCE_ID(input); + FragInputs output; + ZERO_INITIALIZE(FragInputs, output); + + // Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). + // TODO: this is a really poor workaround, but the variable is used in a bunch of places + // to compute normals which are then passed on elsewhere to compute other values... + output.tangentToWorld = k_identity3x3; + output.positionSS = input.pos; // input.positionCS is SV_Position + // BETTER SHADERS: because we transform world position into actual world space for things like + // triplanar, etc, we have to back transform it here for lighting + output.positionRWS = GetCameraRelativePositionWS(input.worldPos); + output.tangentToWorld = BuildTangentToWorld(input.worldTangent, input.worldNormal); + output.texCoord0 = input.texcoord0; + output.texCoord1 = input.texcoord1; + output.texCoord2 = input.texcoord2; + + return output; + } + +#if UNITY_VERSION > UNITY_2022_3_12 + void ApplyDecalAndGetNormal(FragInputs fragInputs, PositionInputs posInput, Surface surfaceDescription, float3 normalTS, + inout SurfaceData surfaceData) + { + float3 doubleSidedConstants = GetDoubleSidedConstants(); + + #ifdef DECAL_NORMAL_BLENDING + // SG nodes don't ouptut surface gradients, so if decals require surf grad blending, we have to convert + // the normal to gradient before applying the decal. We then have to resolve the gradient back to world space + normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, + fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]); + + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + + GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants); + #else + // normal delivered to master node + + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz); + ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData); + } + #endif + #endif + } +#endif + + void BuildSurfaceData(FragInputs fragInputs, inout Surface surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS) + { + // setup defaults -- these are used if the graph doesn't output a value + ZERO_INITIALIZE(SurfaceData, surfaceData); + + // specularOcclusion need to be init ahead of decal to quiet the compiler that modify the SurfaceData struct + // however specularOcclusion can come from the graph, so need to be init here so it can be override. + surfaceData.specularOcclusion = 1.0; + + // copy across graph values, if defined + surfaceData.baseColor = surfaceDescription.Albedo; + surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; + surfaceData.ambientOcclusion = surfaceDescription.Occlusion; + surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; + surfaceData.metallic = surfaceDescription.Metallic; + surfaceData.subsurfaceMask = surfaceDescription.SubsurfaceMask; + surfaceData.thickness = surfaceDescription.Thickness; + surfaceData.diffusionProfileHash = asuint(surfaceDescription.DiffusionProfileHash); + #if _USESPECULAR + surfaceData.specularColor = surfaceDescription.Specular; + #endif + surfaceData.coatMask = surfaceDescription.CoatMask; + surfaceData.anisotropy = surfaceDescription.Anisotropy; + surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; + surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; + + + + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) + if (_EnableSSRefraction) + { + surfaceData.transmittanceMask = (1.0 - surfaceDescription.Alpha); + surfaceDescription.Alpha = 1.0; + } + else + { + surfaceData.ior = surfaceDescription.ior; + surfaceData.transmittanceColor = surfaceDescription.transmittanceColor; + surfaceData.atDistance = surfaceDescription.atDistance; + surfaceData.transmittanceMask = surfaceDescription.transmittanceMask; + surfaceDescription.Alpha = 1.0; + } + #else + surfaceData.ior = 1.0; + surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); + surfaceData.atDistance = 1.0; + surfaceData.transmittanceMask = 0.0; + #endif + + + + // These static material feature allow compile time optimization + surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; + #ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; + #endif + + #ifdef _MATERIAL_FEATURE_TRANSMISSION + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; + #endif + + #ifdef _MATERIAL_FEATURE_ANISOTROPY + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; + surfaceData.normalWS = float3(0, 1, 0); + #endif + + #ifdef _MATERIAL_FEATURE_IRIDESCENCE + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; + #endif + + #ifdef _MATERIAL_FEATURE_SPECULAR_COLOR + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; + #endif + + #if defined(_MATERIAL_FEATURE_CLEAR_COAT) || _CLEARCOAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif + + #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) + // Require to have setup baseColor + // Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it + surfaceData.baseColor *= (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)); + #endif + + float3 normalTS = surfaceDescription.Normal; + #if !_WORLDSPACENORMAL + surfaceData.normalWS = mul(surfaceDescription.Normal, fragInputs.tangentToWorld); + #else + normalTS = mul(fragInputs.tangentToWorld, surfaceDescription.Normal); + surfaceData.normalWS = surfaceDescription.Normal; + #endif + + + #if UNITY_VERSION > UNITY_2022_3_12 + ApplyDecalAndGetNormal(fragInputs, posInput, surfaceDescription, normalTS, surfaceData); + #else + #ifdef DECAL_NORMAL_BLENDING + #if HAVE_DECALS + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + if (_EnableDecals) + { + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData, normalTS); + } + #endif + #else + #if HAVE_DECALS + if (_EnableDecals) + { + float alpha = 1.0; + alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha); + ApplyDecalToSurfaceData(decalSurfaceData, fragInputs.tangentToWorld[2], surfaceData); + } + #endif + #endif + #endif + + + + surfaceData.geomNormalWS = fragInputs.tangentToWorld[2]; + + surfaceData.tangentWS = normalize(fragInputs.tangentToWorld[0].xyz); // The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT + + + bentNormalWS = surfaceData.normalWS; + + surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); + + #ifdef DEBUG_DISPLAY + if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) + { + // TODO: need to update mip info + surfaceData.metallic = 0; + } + + // We need to call ApplyDebugToSurfaceData after filling the surfarcedata and before filling builtinData + // as it can modify attribute use for static lighting + ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData); + #endif + + // By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. + // If user provide bent normal then we process a better term + #if defined(_SPECULAR_OCCLUSION_CUSTOM) + // Just use the value passed through via the slot (not active otherwise) + #elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL) + // If we have bent normal and ambient occlusion, process a specular occlusion + surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness)); + #elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO) + surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); + #endif + + #if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING) + surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold); + #endif + } + + void GetSurfaceAndBuiltinData(VertexToPixel m2ps, FragInputs fragInputs, float3 V, inout PositionInputs posInput, + out SurfaceData surfaceData, out BuiltinData builtinData, inout Surface l, inout ShaderData d + #if NEED_FACING + , bool facing + #endif + ) + { + // Removed since crossfade does not work, probably needs extra material setup. + //#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT) + // #ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group + // LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x); + // #endif + //#endif + + + + + d = CreateShaderData(m2ps + #if NEED_FACING + , facing + #endif + ); + + l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + l.SpecularOcclusion = 1; + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + l.outputDepth = d.clipPos.z; + #endif + + ChainSurfaceFunction(l, d); + + #if !defined(SHADER_STAGE_RAY_TRACING) && defined(_DEPTHOFFSET_ON) + posInput.deviceDepth = l.outputDepth; + #endif + + #if _UNLIT + //l.Emission = l.Albedo; + //l.Albedo = 0; + l.Normal = half3(0,0,1); + l.Occlusion = 1; + l.Metallic = 0; + l.Specular = 0; + #endif + + surfaceData.geomNormalWS = d.worldSpaceNormal; + surfaceData.tangentWS = d.worldSpaceTangent; + fragInputs.tangentToWorld = d.TBNMatrix; + + float3 bentNormalWS; + + BuildSurfaceData(fragInputs, l, V, posInput, surfaceData, bentNormalWS); + + + float4 lightmapTexCoord1 = fragInputs.texCoord1; + float4 lightmapTexCoord2 = fragInputs.texCoord2; + //#ifdef FRAG_INPUTS_USE_TEXCOORD1 + // float4 lightmapTexCoord1 = fragInputs.texCoord1; + // #else + // float4 lightmapTexCoord1 = float4(0,0,0,0); + // #endif + + // #ifdef FRAG_INPUTS_USE_TEXCOORD2 + // float4 lightmapTexCoord2 = fragInputs.texCoord2; + // #else + // float4 lightmapTexCoord2 = float4(0,0,0,0); + // #endif + + + InitBuiltinData(posInput, l.Alpha, bentNormalWS, -d.worldSpaceNormal, lightmapTexCoord1, lightmapTexCoord2, builtinData); + + + + builtinData.emissiveColor = l.Emission; + + #if defined(_OVERRIDE_BAKEDGI) + builtinData.bakeDiffuseLighting = l.DiffuseGI; + builtinData.backBakeDiffuseLighting = l.BackDiffuseGI; + builtinData.emissiveColor += l.SpecularGI; + #endif + + #if defined(_OVERRIDE_SHADOWMASK) + builtinData.shadowMask0 = l.ShadowMask.x; + builtinData.shadowMask1 = l.ShadowMask.y; + builtinData.shadowMask2 = l.ShadowMask.z; + builtinData.shadowMask3 = l.ShadowMask.w; + #endif + + #ifdef UNITY_VIRTUAL_TEXTURING + //builtinData.vtPackedFeedback = surfaceData.VTPackedFeedback; + #endif + + #if (SHADERPASS == SHADERPASS_DISTORTION) + builtinData.distortion = surfaceData.Distortion; + builtinData.distortionBlur = surfaceData.DistortionBlur; + #endif + + #ifndef SHADER_UNLIT + // PostInitBuiltinData call ApplyDebugToBuiltinData + PostInitBuiltinData(V, posInput, surfaceData, builtinData); + #else + ApplyDebugToBuiltinData(builtinData); + #endif + + RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS + } + + + +#define DEBUG_DISPLAY +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/FullScreenDebug.hlsl" + + #if !defined(_DEPTHOFFSET_ON) + [earlydepthstencil] // quad overshading debug mode writes to UAV + #endif + void Frag(VertexToPixel v2f + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(v2f); + FragInputs input = BuildFragInputs(v2f); + + PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz); + + #ifdef PLATFORM_SUPPORTS_PRIMITIVE_ID_IN_PIXEL_SHADER + if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_QUAD_OVERDRAW) + { + IncrementQuadOverdrawCounter(posInput.positionSS.xy, input.primitiveID); + } + #endif + } + + ENDHLSL + } + + + + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2023.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2023.txt.meta new file mode 100644 index 0000000..e73c1ae --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2023.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: a1f8afb0017813b4aac0394c15f9f2a5 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_HDRP2023.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_Standard.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_Standard.txt new file mode 100644 index 0000000..193a02b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_Standard.txt @@ -0,0 +1,17416 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: Standard +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + } + SubShader + { + Tags { "RenderType" = "Opaque" "Queue" = "Geometry" } + + + + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + CGPROGRAM + // compile directives + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + #pragma multi_compile_instancing + #pragma multi_compile_fog + #pragma multi_compile_fwdbase + #include "HLSLSupport.cginc" + #define UNITY_INSTANCED_LOD_FADE + #define UNITY_INSTANCED_SH + #define UNITY_INSTANCED_LIGHTMAPSTS + + #include "UnityShaderVariables.cginc" + #include "UnityShaderUtilities.cginc" + // -------- variant for: + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + #include "AutoLight.cginc" + #define SHADER_PASS SHADERPASS_FORWARD + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _STANDARD 1 +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_GAMECORE) + + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r + #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_XBOXONE) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_PSSL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName + #define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + + +#elif defined(SHADER_API_D3D11) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined + // TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) + // This file assume SHADER_API_SWITCH is defined + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + + // OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 46) + #define OPENGL4_1_SM5 1 + #else + #define OPENGL4_1_SM5 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + + #if OPENGL4_1_SM5 + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #endif + + + #elif defined(SHADER_API_GLES3) + + // GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 40) + #define GLES3_1_AEP 1 + #else + #define GLES3_1_AEP 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #if GLES3_1_AEP + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + #else + #define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + #endif + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #if GLES3_1_AEP + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + #endif + + +#elif defined(SHADER_API_GLES) + + + #define uint int + + #define rcp(x) 1.0 / (x) + #define ddx_fine ddx + #define ddy_fine ddy + #define asfloat + #define asuint(x) asint(x) + #define f32tof16 + #define f16tof32 + + #define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + + // Texture abstraction + + #define TEXTURE2D(textureName) sampler2D textureName + #define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray + #define TEXTURECUBE(textureName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray + #define TEXTURE3D(textureName) sampler3D textureName + + #define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray + #define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray + #define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + + #define TEXTURE2D_HALF(textureName) sampler2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray + #define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray + #define TEXTURE3D_HALF(textureName) sampler3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + #define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + + #define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + + #define SAMPLER(samplerName) + #define SAMPLER_CMP(samplerName) + + #define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + + #if (SHADER_TARGET >= 30) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) + #else + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) + #endif + + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + + + // Not supported. Can't define as error because shader library is calling these functions. + #define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + + // Gather not supported. Fallback to regular texture sampling. + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + + + + +// default flow control attributes +#ifndef UNITY_BRANCH +# define UNITY_BRANCH +#endif +#ifndef UNITY_FLATTEN +# define UNITY_FLATTEN +#endif +#ifndef UNITY_UNROLL +# define UNITY_UNROLL +#endif +#ifndef UNITY_UNROLLX +# define UNITY_UNROLLX(_x) +#endif +#ifndef UNITY_LOOP +# define UNITY_LOOP +#endif + + + +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // data across stages, stripped like the above. + struct VertexToPixel + { + UNITY_POSITION(pos); + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + float4 lmap : TEXCOORD8; + #if UNITY_SHOULD_SAMPLE_SH + half3 sh : TEXCOORD9; // SH + #endif + #ifdef LIGHTMAP_ON + UNITY_LIGHTING_COORDS(10,11) + UNITY_FOG_COORDS(12) + #else + UNITY_FOG_COORDS(10) + UNITY_SHADOW_COORDS(11) + #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef UNITY_MATRIX_I_M + + #define UNITY_MATRIX_I_M unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)UNITY_MATRIX_V, norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + UNITY_SETUP_INSTANCE_ID(v); + VertexToPixel o; + UNITY_INITIALIZE_OUTPUT(VertexToPixel,o); + UNITY_TRANSFER_INSTANCE_ID(v,o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos); + // #endif + + o.worldPos = mul(GetObjectToWorldMatrix(), v.vertex).xyz; + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + #ifdef DYNAMICLIGHTMAP_ON + o.lmap.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + #ifdef LIGHTMAP_ON + o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + #endif + + // SH/ambient and vertex lights + #ifndef LIGHTMAP_ON + #if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL + o.sh = 0; + // Approximated illumination from non-important point lights + #ifdef VERTEXLIGHT_ON + o.sh += Shade4PointLights ( + unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0, + unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb, + unity_4LightAtten0, o.worldPos, o.worldNormal); + #endif + o.sh = ShadeSHPerVertex (o.worldNormal, o.sh); + #endif + #endif // !LIGHTMAP_ON + + UNITY_TRANSFER_LIGHTING(o,v.texcoord1.xy); // pass shadow and, possibly, light cookie coordinates to pixel shader + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_TRANSFER_FOG_COMBINED_WITH_TSPACE(o,o.pos); // pass fog coordinates to pixel shader + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_TRANSFER_FOG_COMBINED_WITH_WORLD_POS(o,o.pos); // pass fog coordinates to pixel shader + #else + UNITY_TRANSFER_FOG(o,o.pos); // pass fog coordinates to pixel shader + #endif + + return o; + } + + + + // fragment shader + fixed4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + // prepare and unpack data + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_EXTRACT_FOG_FROM_TSPACE(IN); + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN); + #else + UNITY_EXTRACT_FOG(IN); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + + #ifndef USING_DIRECTIONAL_LIGHT + fixed3 lightDir = normalize(UnityWorldSpaceLightDir(d.worldSpacePosition)); + #else + fixed3 lightDir = _WorldSpaceLightPos0.xyz; + #endif + float3 worldViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + + // compute lighting & shadowing factor + UNITY_LIGHT_ATTENUATION(atten, IN, d.worldSpacePosition) + + #if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0; + #else + SurfaceOutputStandardSpecular o; + #endif + o.Specular = l.Specular; + o.Occlusion = l.Occlusion; + o.Smoothness = l.Smoothness; + #elif _BDRFLAMBERT || _BDRF3 || _SIMPLELIT + #ifdef UNITY_COMPILER_HLSL + SurfaceOutput o = (SurfaceOutput)0; + #else + SurfaceOutput o; + #endif + + o.Specular = l.Specular; + o.Gloss = l.Smoothness; + _SpecColor.rgb = l.Specular; // fucking hell Unity, wtf.. + #else + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandard o = (SurfaceOutputStandard)0; + #else + SurfaceOutputStandard o; + #endif + o.Smoothness = l.Smoothness; + o.Metallic = l.Metallic; + o.Occlusion = l.Occlusion; + #endif + + o.Albedo = l.Albedo; + o.Emission = l.Emission; + o.Alpha = l.Alpha; + #if _WORLDSPACENORMAL + o.Normal = l.Normal; + #else + o.Normal = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + fixed4 c = 0; + // Setup lighting environment + UnityGI gi; + UNITY_INITIALIZE_OUTPUT(UnityGI, gi); + gi.indirect.diffuse = 0; + gi.indirect.specular = 0; + gi.light.color = _LightColor0.rgb; + gi.light.dir = lightDir; + // Call GI (lightmaps/SH/reflections) lighting function + UnityGIInput giInput; + UNITY_INITIALIZE_OUTPUT(UnityGIInput, giInput); + giInput.light = gi.light; + giInput.worldPos = d.worldSpacePosition; + giInput.worldViewDir = worldViewDir; + giInput.atten = atten; + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + giInput.lightmapUV = IN.lmap; + #else + giInput.lightmapUV = 0.0; + #endif + #if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL + giInput.ambient = IN.sh; + #else + giInput.ambient.rgb = 0.0; + #endif + giInput.probeHDR[0] = unity_SpecCube0_HDR; + giInput.probeHDR[1] = unity_SpecCube1_HDR; + #if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION) + giInput.boxMin[0] = unity_SpecCube0_BoxMin; // .w holds lerp value for blending + #endif + #ifdef UNITY_SPECCUBE_BOX_PROJECTION + giInput.boxMax[0] = unity_SpecCube0_BoxMax; + giInput.probePosition[0] = unity_SpecCube0_ProbePosition; + giInput.boxMax[1] = unity_SpecCube1_BoxMax; + giInput.boxMin[1] = unity_SpecCube1_BoxMin; + giInput.probePosition[1] = unity_SpecCube1_ProbePosition; + #endif + + + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, unity_OcclusionMaskSelector)); + gi.light.color *= mulColor; + giInput.light.color *= mulColor; + #endif + + #if _UNLIT + c.rgb = l.Albedo; + c.a = l.Alpha; + #elif _BDRF3 || _SIMPLELIT + LightingBlinnPhong_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + c += LightingBlinnPhong (o, d.worldSpaceViewDir, gi); + #elif _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC + LightingStandardSpecular_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + c += LightingStandardSpecular (o, d.worldSpaceViewDir, gi); + #else + LightingStandard_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + c += LightingStandard (o, d.worldSpaceViewDir, gi); + #endif + + c.rgb += o.Emission; + + ChainFinalColorForward(l, d, c); + + #if !DISABLEFOG + UNITY_APPLY_FOG(_unity_fogCoord, c); // apply fog + #endif + + + return c; + } + + ENDCG + + } + + + + // ---- deferred shading pass: + Pass + { + Name "DEFERRED" + Tags { "LightMode" = "Deferred" } + + Cull [_CullingOption] + + + CGPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + // compile directives + #pragma target 3.0 + #pragma multi_compile_instancing + #pragma exclude_renderers nomrt + #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2 + #pragma multi_compile_prepassfinal + #include "HLSLSupport.cginc" + #define UNITY_INSTANCED_LOD_FADE + #define UNITY_INSTANCED_SH + #define UNITY_INSTANCED_LIGHTMAPSTS + #include "UnityShaderVariables.cginc" + #include "UnityShaderUtilities.cginc" + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + + #define _PASSGBUFFER 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _STANDARD 1 +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_GAMECORE) + + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r + #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_XBOXONE) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_PSSL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName + #define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + + +#elif defined(SHADER_API_D3D11) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined + // TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) + // This file assume SHADER_API_SWITCH is defined + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + + // OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 46) + #define OPENGL4_1_SM5 1 + #else + #define OPENGL4_1_SM5 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + + #if OPENGL4_1_SM5 + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #endif + + + #elif defined(SHADER_API_GLES3) + + // GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 40) + #define GLES3_1_AEP 1 + #else + #define GLES3_1_AEP 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #if GLES3_1_AEP + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + #else + #define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + #endif + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #if GLES3_1_AEP + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + #endif + + +#elif defined(SHADER_API_GLES) + + + #define uint int + + #define rcp(x) 1.0 / (x) + #define ddx_fine ddx + #define ddy_fine ddy + #define asfloat + #define asuint(x) asint(x) + #define f32tof16 + #define f16tof32 + + #define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + + // Texture abstraction + + #define TEXTURE2D(textureName) sampler2D textureName + #define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray + #define TEXTURECUBE(textureName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray + #define TEXTURE3D(textureName) sampler3D textureName + + #define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray + #define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray + #define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + + #define TEXTURE2D_HALF(textureName) sampler2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray + #define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray + #define TEXTURE3D_HALF(textureName) sampler3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + #define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + + #define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + + #define SAMPLER(samplerName) + #define SAMPLER_CMP(samplerName) + + #define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + + #if (SHADER_TARGET >= 30) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) + #else + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) + #endif + + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + + + // Not supported. Can't define as error because shader library is calling these functions. + #define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + + // Gather not supported. Fallback to regular texture sampling. + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + + + + +// default flow control attributes +#ifndef UNITY_BRANCH +# define UNITY_BRANCH +#endif +#ifndef UNITY_FLATTEN +# define UNITY_FLATTEN +#endif +#ifndef UNITY_UNROLL +# define UNITY_UNROLL +#endif +#ifndef UNITY_UNROLLX +# define UNITY_UNROLLX(_x) +#endif +#ifndef UNITY_LOOP +# define UNITY_LOOP +#endif + + + +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + UNITY_POSITION(pos); // must be named pos because Unity does stupid macro stuff + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + #ifndef DIRLIGHTMAP_OFF + float3 viewDir : TEXCOORD8; + #endif + float4 lmap : TEXCOORD9; + #ifndef LIGHTMAP_ON + #if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL + half3 sh : TEXCOORD10; // SH + #endif + #else + #ifdef DIRLIGHTMAP_OFF + float4 lmapFadePos : TEXCOORD11; + #endif + #endif + + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD19; + // #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef UNITY_MATRIX_I_M + + #define UNITY_MATRIX_I_M unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)UNITY_MATRIX_V, norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + // vertex shader + VertexToPixel Vert (VertexData v) + { + UNITY_SETUP_INSTANCE_ID(v); + VertexToPixel o; + UNITY_INITIALIZE_OUTPUT(VertexToPixel,o); + UNITY_TRANSFER_INSTANCE_ID(v,o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos); + // #endif + + o.worldPos = mul(GetObjectToWorldMatrix(), v.vertex).xyz; + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + float3 viewDirForLight = UnityWorldSpaceViewDir(o.worldPos); + #ifndef DIRLIGHTMAP_OFF + float3 worldBinormal = cross(o.worldNormal, o.worldTangent.xyz); + o.viewDir.x = dot(viewDirForLight, o.worldTangent.xyz); + o.viewDir.y = dot(viewDirForLight, worldBinormal); + o.viewDir.z = dot(viewDirForLight, o.worldNormal); + #endif + #ifdef DYNAMICLIGHTMAP_ON + o.lmap.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #else + o.lmap.zw = 0; + #endif + #ifdef LIGHTMAP_ON + o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + #ifdef DIRLIGHTMAP_OFF + o.lmapFadePos.xyz = (mul(GetObjectToWorldMatrix(), v.vertex).xyz - unity_ShadowFadeCenterAndType.xyz) * unity_ShadowFadeCenterAndType.w; + o.lmapFadePos.w = (-UnityObjectToViewPos(v.vertex).z) * (1.0 - unity_ShadowFadeCenterAndType.w); + #endif + #else + o.lmap.xy = 0; + #if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL + o.sh = 0; + o.sh = ShadeSHPerVertex (o.worldNormal, o.sh); + #endif + #endif + + return o; + } + + + + #ifdef LIGHTMAP_ON + float4 unity_LightmapFade; + #endif + fixed4 unity_Ambient; + + + + // fragment shader + void Frag (VertexToPixel IN, + out half4 outGBuffer0 : SV_Target0, + out half4 outGBuffer1 : SV_Target1, + out half4 outGBuffer2 : SV_Target2, + out half4 outEmission : SV_Target3 + #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + , out half4 outShadowMask : SV_Target4 + #endif + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_INSTANCE_ID(IN); + // prepare and unpack data + + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_EXTRACT_FOG_FROM_TSPACE(IN); + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN); + #else + UNITY_EXTRACT_FOG(IN); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + + + + + #ifndef USING_DIRECTIONAL_LIGHT + fixed3 lightDir = normalize(UnityWorldSpaceLightDir(d.worldSpacePosition)); + #else + fixed3 lightDir = _WorldSpaceLightPos0.xyz; + #endif + float3 worldViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + + #if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0; + #else + SurfaceOutputStandardSpecular o; + #endif + o.Specular = l.Specular; + o.Occlusion = l.Occlusion; + o.Smoothness = l.Smoothness; + #elif _BDRFLAMBERT || _BDRF3 || _SIMPLELIT + #ifdef UNITY_COMPILER_HLSL + SurfaceOutput o = (SurfaceOutput)0; + #else + SurfaceOutput o; + #endif + + o.Specular = l.SpecularPower; + o.Gloss = l.Smoothness; + _SpecColor.rgb = l.Specular; // fucking hell Unity, wtf.. + #else + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandard o = (SurfaceOutputStandard)0; + #else + SurfaceOutputStandard o; + #endif + o.Smoothness = l.Smoothness; + o.Metallic = l.Metallic; + o.Occlusion = l.Occlusion; + #endif + + + + o.Albedo = l.Albedo; + o.Emission = l.Emission; + o.Alpha = l.Alpha; + + #if _WORLDSPACENORMAL + o.Normal = l.Normal; + #else + o.Normal = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + + half atten = 1; + + // Setup lighting environment + UnityGI gi; + UNITY_INITIALIZE_OUTPUT(UnityGI, gi); + gi.indirect.diffuse = 0; + gi.indirect.specular = 0; + gi.light.color = 0; + gi.light.dir = half3(0,1,0); + // Call GI (lightmaps/SH/reflections) lighting function + UnityGIInput giInput; + UNITY_INITIALIZE_OUTPUT(UnityGIInput, giInput); + giInput.light = gi.light; + giInput.worldPos = d.worldSpacePosition; + giInput.worldViewDir = worldViewDir; + giInput.atten = atten; + #if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) + giInput.lightmapUV = IN.lmap; + #else + giInput.lightmapUV = 0.0; + #endif + #if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL + giInput.ambient = IN.sh; + #else + giInput.ambient.rgb = 0.0; + #endif + giInput.probeHDR[0] = unity_SpecCube0_HDR; + giInput.probeHDR[1] = unity_SpecCube1_HDR; + #if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION) + giInput.boxMin[0] = unity_SpecCube0_BoxMin; // .w holds lerp value for blending + #endif + #ifdef UNITY_SPECCUBE_BOX_PROJECTION + giInput.boxMax[0] = unity_SpecCube0_BoxMax; + giInput.probePosition[0] = unity_SpecCube0_ProbePosition; + giInput.boxMax[1] = unity_SpecCube1_BoxMax; + giInput.boxMin[1] = unity_SpecCube1_BoxMin; + giInput.probePosition[1] = unity_SpecCube1_ProbePosition; + #endif + + + + #if _BDRF3 || _SIMPLELIT + + LightingBlinnPhong_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + + outEmission = LightingBlinnPhong_Deferred(o, worldViewDir, gi, outGBuffer0, outGBuffer1, outGBuffer2); + #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + outShadowMask = UnityGetRawBakedOcclusions (IN.lmap.xy, d.worldSpacePosition); + #endif + #ifndef UNITY_HDR_ON + outEmission.rgb = exp2(-outEmission.rgb); + #endif + #elif _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC + LightingStandardSpecular_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + // call lighting function to output g-buffer + outEmission = LightingStandardSpecular_Deferred (o, worldViewDir, gi, outGBuffer0, outGBuffer1, outGBuffer2); + #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + outShadowMask = UnityGetRawBakedOcclusions (IN.lmap.xy, d.worldSpacePosition); + #endif + #ifndef UNITY_HDR_ON + outEmission.rgb = exp2(-outEmission.rgb); + #endif + #else + LightingStandard_GI(o, giInput, gi); + #if defined(_OVERRIDE_BAKEDGI) + gi.indirect.diffuse = l.DiffuseGI; + gi.indirect.specular = l.SpecularGI; + #endif + // call lighting function to output g-buffer + outEmission = LightingStandard_Deferred (o, worldViewDir, gi, outGBuffer0, outGBuffer1, outGBuffer2); + #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + outShadowMask = UnityGetRawBakedOcclusions (IN.lmap.xy, d.worldSpacePosition); + #endif + #ifndef UNITY_HDR_ON + outEmission.rgb = exp2(-outEmission.rgb); + #endif + #endif + + #if defined(_OVERRIDE_SHADOWMASK) && defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + float4 mulColor = saturate(dot(l.ShadowMask, unity_OcclusionMaskSelector)); + outShadowMask = mulColor; + #endif + + #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + ChainFinalGBufferStandard(l, d, outGBuffer0, outGBuffer1, outGBuffer2, outEmission, outShadowMask); + #else + half4 outShadowMask = 0; + ChainFinalGBufferStandard(l, d, outGBuffer0, outGBuffer1, outGBuffer2, outEmission, outShadowMask); + #endif + + + } + + + + + ENDCG + + } + + + + + // ---- forward rendering additive lights pass: + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardAdd" } + ZWrite Off Blend One One + + + + CGPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + // compile directives + #pragma target 3.0 + #pragma multi_compile_instancing + #pragma multi_compile_fog + #pragma skip_variants INSTANCING_ON + #pragma multi_compile_fwdadd_fullshadows + #include "HLSLSupport.cginc" + #define UNITY_INSTANCED_LOD_FADE + #define UNITY_INSTANCED_SH + #define UNITY_INSTANCED_LIGHTMAPSTS + #include "UnityShaderVariables.cginc" + #include "UnityShaderUtilities.cginc" + + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + #include "AutoLight.cginc" + + + + #define _PASSFORWARD 1 + #define _PASSFORWARDADD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _STANDARD 1 +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_GAMECORE) + + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r + #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_XBOXONE) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_PSSL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName + #define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + + +#elif defined(SHADER_API_D3D11) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined + // TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) + // This file assume SHADER_API_SWITCH is defined + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + + // OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 46) + #define OPENGL4_1_SM5 1 + #else + #define OPENGL4_1_SM5 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + + #if OPENGL4_1_SM5 + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #endif + + + #elif defined(SHADER_API_GLES3) + + // GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 40) + #define GLES3_1_AEP 1 + #else + #define GLES3_1_AEP 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #if GLES3_1_AEP + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + #else + #define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + #endif + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #if GLES3_1_AEP + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + #endif + + +#elif defined(SHADER_API_GLES) + + + #define uint int + + #define rcp(x) 1.0 / (x) + #define ddx_fine ddx + #define ddy_fine ddy + #define asfloat + #define asuint(x) asint(x) + #define f32tof16 + #define f16tof32 + + #define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + + // Texture abstraction + + #define TEXTURE2D(textureName) sampler2D textureName + #define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray + #define TEXTURECUBE(textureName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray + #define TEXTURE3D(textureName) sampler3D textureName + + #define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray + #define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray + #define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + + #define TEXTURE2D_HALF(textureName) sampler2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray + #define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray + #define TEXTURE3D_HALF(textureName) sampler3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + #define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + + #define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + + #define SAMPLER(samplerName) + #define SAMPLER_CMP(samplerName) + + #define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + + #if (SHADER_TARGET >= 30) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) + #else + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) + #endif + + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + + + // Not supported. Can't define as error because shader library is calling these functions. + #define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + + // Gather not supported. Fallback to regular texture sampling. + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + + + + +// default flow control attributes +#ifndef UNITY_BRANCH +# define UNITY_BRANCH +#endif +#ifndef UNITY_FLATTEN +# define UNITY_FLATTEN +#endif +#ifndef UNITY_UNROLL +# define UNITY_UNROLL +#endif +#ifndef UNITY_UNROLLX +# define UNITY_UNROLLX(_x) +#endif +#ifndef UNITY_LOOP +# define UNITY_LOOP +#endif + + + +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // data across stages, stripped like the above. + struct VertexToPixel + { + UNITY_POSITION(pos); // must be named pos because Unity does stupid macro stuff + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + UNITY_LIGHTING_COORDS(8,9) + UNITY_FOG_COORDS(10) + + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD18; + // #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + + }; + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef UNITY_MATRIX_I_M + + #define UNITY_MATRIX_I_M unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)UNITY_MATRIX_V, norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + UNITY_SETUP_INSTANCE_ID(v); + VertexToPixel o; + UNITY_INITIALIZE_OUTPUT(VertexToPixel,o); + UNITY_TRANSFER_INSTANCE_ID(v,o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.pos = UnityObjectToClipPos(v.vertex); + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos); + // #endif + + o.worldPos = mul(GetObjectToWorldMatrix(), v.vertex).xyz; + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + UNITY_TRANSFER_LIGHTING(o, v.texcoord1.xy); // pass shadow and, possibly, light cookie coordinates to pixel shader + UNITY_TRANSFER_FOG(o,o.pos); // pass fog coordinates to pixel shader + + return o; + } + + + + // fragment shader + fixed4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + // prepare and unpack data + + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_EXTRACT_FOG_FROM_TSPACE(IN); + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN); + #else + UNITY_EXTRACT_FOG(IN); + #endif + + + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + + #ifndef USING_DIRECTIONAL_LIGHT + fixed3 lightDir = normalize(UnityWorldSpaceLightDir(d.worldSpacePosition)); + #else + fixed3 lightDir = _WorldSpaceLightPos0.xyz; + #endif + float3 worldViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + + #if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0; + #else + SurfaceOutputStandardSpecular o; + #endif + o.Specular = l.Specular; + o.Occlusion = l.Occlusion; + o.Smoothness = l.Smoothness; + #elif _BDRFLAMBERT || _BDRF3 || _SIMPLELIT + #ifdef UNITY_COMPILER_HLSL + SurfaceOutput o = (SurfaceOutput)0; + #else + SurfaceOutput o; + #endif + + o.Specular = l.SpecularPower; + o.Gloss = l.Smoothness; + _SpecColor.rgb = l.Specular; // fucking hell Unity, wtf.. + #else + #ifdef UNITY_COMPILER_HLSL + SurfaceOutputStandard o = (SurfaceOutputStandard)0; + #else + SurfaceOutputStandard o; + #endif + o.Smoothness = l.Smoothness; + o.Metallic = l.Metallic; + o.Occlusion = l.Occlusion; + #endif + + + o.Albedo = l.Albedo; + o.Emission = l.Emission; + o.Alpha = l.Alpha; + + #if _WORLDSPACENORMAL + o.Normal = l.Normal; + #else + o.Normal = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + + + UNITY_LIGHT_ATTENUATION(atten, IN, d.worldSpacePosition) + half4 c = 0; + + // Setup lighting environment + UnityGI gi; + UNITY_INITIALIZE_OUTPUT(UnityGI, gi); + gi.indirect.diffuse = 0; + gi.indirect.specular = 0; + gi.light.color = _LightColor0.rgb; + gi.light.dir = lightDir; + gi.light.color *= atten; + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, unity_OcclusionMaskSelector)); + gi.light.color *= mulColor; + #endif + + #if _USESPECULAR + c += LightingStandardSpecular (o, worldViewDir, gi); + #elif _BDRF3 || _SIMPLELIT + c += LightingBlinnPhong (o, d.worldSpaceViewDir, gi); + #else + c += LightingStandard (o, worldViewDir, gi); + #endif + + + ChainFinalColorForward(l, d, c); + + #if !DISABLEFOG + UNITY_APPLY_FOG(_unity_fogCoord, c); // apply fog + #endif + #if !_ALPHABLEND_ON + UNITY_OPAQUE_ALPHA(c.a); + #endif + + return c; + } + + ENDCG + + } + + + Pass { + Name "ShadowCaster" + Tags { "LightMode" = "ShadowCaster" } + ZWrite On ZTest LEqual + + + + CGPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + // compile directives + #pragma target 3.0 + #pragma multi_compile_instancing + #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2 + #pragma multi_compile_shadowcaster + #include "HLSLSupport.cginc" + #define UNITY_INSTANCED_LOD_FADE + #define UNITY_INSTANCED_SH + #define UNITY_INSTANCED_LIGHTMAPSTS + #include "UnityShaderVariables.cginc" + #include "UnityShaderUtilities.cginc" + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _STANDARD 1 +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_GAMECORE) + + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r + #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_XBOXONE) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_PSSL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName + #define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + + +#elif defined(SHADER_API_D3D11) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined + // TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) + // This file assume SHADER_API_SWITCH is defined + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + + // OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 46) + #define OPENGL4_1_SM5 1 + #else + #define OPENGL4_1_SM5 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + + #if OPENGL4_1_SM5 + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #endif + + + #elif defined(SHADER_API_GLES3) + + // GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 40) + #define GLES3_1_AEP 1 + #else + #define GLES3_1_AEP 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #if GLES3_1_AEP + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + #else + #define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + #endif + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #if GLES3_1_AEP + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + #endif + + +#elif defined(SHADER_API_GLES) + + + #define uint int + + #define rcp(x) 1.0 / (x) + #define ddx_fine ddx + #define ddy_fine ddy + #define asfloat + #define asuint(x) asint(x) + #define f32tof16 + #define f16tof32 + + #define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + + // Texture abstraction + + #define TEXTURE2D(textureName) sampler2D textureName + #define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray + #define TEXTURECUBE(textureName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray + #define TEXTURE3D(textureName) sampler3D textureName + + #define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray + #define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray + #define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + + #define TEXTURE2D_HALF(textureName) sampler2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray + #define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray + #define TEXTURE3D_HALF(textureName) sampler3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + #define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + + #define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + + #define SAMPLER(samplerName) + #define SAMPLER_CMP(samplerName) + + #define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + + #if (SHADER_TARGET >= 30) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) + #else + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) + #endif + + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + + + // Not supported. Can't define as error because shader library is calling these functions. + #define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + + // Gather not supported. Fallback to regular texture sampling. + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + + + + +// default flow control attributes +#ifndef UNITY_BRANCH +# define UNITY_BRANCH +#endif +#ifndef UNITY_FLATTEN +# define UNITY_FLATTEN +#endif +#ifndef UNITY_UNROLL +# define UNITY_UNROLL +#endif +#ifndef UNITY_UNROLLX +# define UNITY_UNROLLX(_x) +#endif +#ifndef UNITY_LOOP +# define UNITY_LOOP +#endif + + + +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + V2F_SHADOW_CASTER; // may declare TEXCOORD0 for the wonderfully named .vec + float3 worldPos : TEXCOORD1; + float3 worldNormal : TEXCOORD2; + float4 worldTangent : TEXCOORD3; + float4 texcoord0 : TEXCOORD4; + float4 texcoord1 : TEXCOORD5; + float4 texcoord2 : TEXCOORD6; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD7; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD8; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD16; + // #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef UNITY_MATRIX_I_M + + #define UNITY_MATRIX_I_M unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)UNITY_MATRIX_V, norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + // vertex shader + VertexToPixel Vert (VertexData v) + { + UNITY_SETUP_INSTANCE_ID(v); + VertexToPixel o; + UNITY_INITIALIZE_OUTPUT(VertexToPixel,o); + UNITY_TRANSFER_INSTANCE_ID(v,o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + + + o.worldPos = mul(GetObjectToWorldMatrix(), v.vertex).xyz; + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + // sets o.pos, so do screenpos after. + TRANSFER_SHADOW_CASTER_NORMALOFFSET(o) + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos); + // #endif + + return o; + } + + + + // fragment shader + fixed4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + // prepare and unpack data + + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_EXTRACT_FOG_FROM_TSPACE(IN); + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN); + #else + UNITY_EXTRACT_FOG(IN); + #endif + + #ifndef USING_DIRECTIONAL_LIGHT + fixed3 lightDir = normalize(UnityWorldSpaceLightDir(IN.worldPos)); + #else + fixed3 lightDir = _WorldSpaceLightPos0.xyz; + #endif + + + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + SHADOW_CASTER_FRAGMENT(IN) + } + + + ENDCG + + } + + + // ---- meta information extraction pass: + Pass + { + Name "Meta" + Tags { "LightMode" = "Meta" } + Cull Off + + + + CGPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + // compile directives + #pragma target 3.0 + #pragma multi_compile_instancing + #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2 + #pragma shader_feature EDITOR_VISUALIZATION + + #include "HLSLSupport.cginc" + #define UNITY_INSTANCED_LOD_FADE + #define UNITY_INSTANCED_SH + #define UNITY_INSTANCED_LIGHTMAPSTS + #include "UnityShaderVariables.cginc" + #include "UnityShaderUtilities.cginc" + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "UnityPBSLighting.cginc" + #include "UnityMetaPass.cginc" + + #define _PASSMETA 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _STANDARD 1 +// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same +// texturing library they use. However, since they are not included in the standard pipeline by default, there is no +// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without +// Better Shaders installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead +// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not +// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there. + +#if defined(SHADER_API_GAMECORE) + + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r + #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_XBOXONE) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + +#elif defined(SHADER_API_PSSL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RW_Texture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RW_Texture2D_Array textureName + #define RW_TEXTURE3D(type, textureName) RW_Texture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + + + +#elif defined(SHADER_API_D3D11) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_METAL) + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_VULKAN) +// This file assume SHADER_API_VULKAN is defined + // TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed. + + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_SWITCH) + // This file assume SHADER_API_SWITCH is defined + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + +#elif defined(SHADER_API_GLCORE) + + // OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 46) + #define OPENGL4_1_SM5 1 + #else + #define OPENGL4_1_SM5 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName) + #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName) + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + + #if OPENGL4_1_SM5 + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #endif + + + #elif defined(SHADER_API_GLES3) + + // GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html + #if (SHADER_TARGET >= 40) + #define GLES3_1_AEP 1 + #else + #define GLES3_1_AEP 0 + #endif + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2) + + // Texture abstraction + + #define TEXTURE2D(textureName) Texture2D textureName + #define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName + #define TEXTURECUBE(textureName) TextureCube textureName + #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName + #define TEXTURE3D(textureName) Texture3D textureName + + #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName + + #define TEXTURE2D_HALF(textureName) Texture2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added + #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray textureName // no support to _float on Array, it's being added + #define TEXTURE3D_HALF(textureName) Texture3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName) + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName) + #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName) + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName) + + #if GLES3_1_AEP + #define RW_TEXTURE2D(type, textureName) RWTexture2D textureName + #define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray textureName + #define RW_TEXTURE3D(type, textureName) RWTexture3D textureName + #else + #define RW_TEXTURE2D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + #endif + + #define SAMPLER(samplerName) SamplerState samplerName + #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName + + #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName) + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName) + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName) + #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName) + + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName) + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName) + #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName) + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName + + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod) + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index)) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias) + + #ifdef UNITY_NO_CUBEMAP_ARRAY + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #else + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index)) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)textureName.SampleBias(samplerName, float4(coord3, index), bias) + #endif + + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w) + + + #define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0)) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod)) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0)) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod)) + #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0)) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod)) + + #if GLES3_1_AEP + #define PLATFORM_SUPPORT_GATHER + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index)) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index)) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2) + #else + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + #endif + + +#elif defined(SHADER_API_GLES) + + + #define uint int + + #define rcp(x) 1.0 / (x) + #define ddx_fine ddx + #define ddy_fine ddy + #define asfloat + #define asuint(x) asint(x) + #define f32tof16 + #define f16tof32 + + #define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0 + + // Initialize arbitrary structure with zero values. + // Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0 + #define ZERO_INITIALIZE(type, name) name = (type)0; + #define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } } + + + // Texture util abstraction + + #define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2 + + // Texture abstraction + + #define TEXTURE2D(textureName) sampler2D textureName + #define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray + #define TEXTURECUBE(textureName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray + #define TEXTURE3D(textureName) sampler3D textureName + + #define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName + #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray + #define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName + #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to textureCubeArray + #define TEXTURE3D_FLOAT(textureName) sampler3D_float textureName + + #define TEXTURE2D_HALF(textureName) sampler2D_half textureName + #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray + #define TEXTURECUBE_HALF(textureName) samplerCUBE_half textureName + #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to textureCubeArray + #define TEXTURE3D_HALF(textureName) sampler3D_half textureName + + #define TEXTURE2D_SHADOW(textureName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + #define TEXTURECUBE_SHADOW(textureName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_SHADOW(textureName) // No support to texture array + + #define RW_TEXTURE2D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2D) + #define RW_TEXTURE2D_ARRAY(type, textureName) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture2DArray) + #define RW_TEXTURE3D(type, textureNam) ERROR_ON_UNSUPPORTED_FUNCTION(RWTexture3D) + + #define SAMPLER(samplerName) + #define SAMPLER_CMP(samplerName) + + #define TEXTURE2D_PARAM(textureName, samplerName) sampler2D textureName + #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) samplerCUBE textureName + #define TEXTURE3D_PARAM(textureName, samplerName) sampler3D textureName + #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) SHADOW2D_TEXTURE_AND_SAMPLER textureName + #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) SHADOWCUBE_TEXTURE_AND_SAMPLER textureName + + #define TEXTURE2D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName + #define TEXTURE3D_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName + #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName + + #define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2) + + #if (SHADER_TARGET >= 30) + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod)) + #else + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod) + #endif + + #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias)) + #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2) + #define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY) + #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD) + #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS) + #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD) + #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) texCUBE(textureName, coord3) + // No lod support. Very poor approximation with bias. + #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, lod) + #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) texCUBEbias(textureName, float4(coord3, bias)) + #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY) + #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_LOD) + #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_BIAS) + #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) tex3D(textureName, coord3) + #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE3D_LOD) + + #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3) + #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_SHADOW) + #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) + #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURECUBE_ARRAY_SHADOW) + + + // Not supported. Can't define as error because shader library is calling these functions. + #define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0) + #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) + #define LOAD_TEXTURE3D(textureName, unCoord3) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D) + #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) ERROR_ON_UNSUPPORTED_FUNCTION(LOAD_TEXTURE3D_LOD) + + // Gather not supported. Fallback to regular texture sampling. + #define GATHER_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D) + #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURE2D_ARRAY) + #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE) + #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_TEXTURECUBE_ARRAY) + #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_RED_TEXTURE2D) + #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_GREEN_TEXTURE2D) + #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_BLUE_TEXTURE2D) + #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) ERROR_ON_UNSUPPORTED_FUNCTION(GATHER_ALPHA_TEXTURE2D) + +#else +#error unsupported shader api +#endif + + + + +// default flow control attributes +#ifndef UNITY_BRANCH +# define UNITY_BRANCH +#endif +#ifndef UNITY_FLATTEN +# define UNITY_FLATTEN +#endif +#ifndef UNITY_UNROLL +# define UNITY_UNROLL +#endif +#ifndef UNITY_UNROLLX +# define UNITY_UNROLLX(_x) +#endif +#ifndef UNITY_LOOP +# define UNITY_LOOP +#endif + + + +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + UNITY_POSITION(pos); + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + #ifdef EDITOR_VISUALIZATION + float2 vizUV : TEXCOORD8; + float4 lightCoord : TEXCOORD9; + #endif + + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD17; + // #endif + + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef UNITY_MATRIX_I_M + + #define UNITY_MATRIX_I_M unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)UNITY_MATRIX_V, norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + UNITY_SETUP_INSTANCE_ID(v); + VertexToPixel o; + UNITY_INITIALIZE_OUTPUT(VertexToPixel,o); + UNITY_TRANSFER_INSTANCE_ID(v,o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + + o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #ifdef EDITOR_VISUALIZATION + o.vizUV = 0; + o.lightCoord = 0; + if (unity_VisualizationMode == EDITORVIZ_TEXTURE) + o.vizUV = UnityMetaVizUV(unity_EditorViz_UVIndex, v.texcoord0.xy, v.texcoord1.xy, v.texcoord2.xy, unity_EditorViz_Texture_ST); + else if (unity_VisualizationMode == EDITORVIZ_SHOWLIGHTMASK) + { + o.vizUV = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; + o.lightCoord = mul(unity_EditorViz_WorldToLight, mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1))); + } + #endif + + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos); + // #endif + + o.worldPos = mul(GetObjectToWorldMatrix(), v.vertex).xyz; + o.worldNormal = UnityObjectToWorldNormal(v.normal); + o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + return o; + } + + + + // fragment shader + fixed4 Frag (VertexToPixel IN + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + #ifdef FOG_COMBINED_WITH_TSPACE + UNITY_EXTRACT_FOG_FROM_TSPACE(IN); + #elif defined FOG_COMBINED_WITH_WORLD_POS + UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN); + #else + UNITY_EXTRACT_FOG(IN); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + + Surface l = (Surface)0; + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + + ChainSurfaceFunction(l, d); + + UnityMetaInput metaIN; + UNITY_INITIALIZE_OUTPUT(UnityMetaInput, metaIN); + metaIN.Albedo = l.Albedo; + metaIN.Emission = l.Emission; + + #if _USESPECULAR + metaIN.SpecularColor = l.Specular; + #endif + + #ifdef EDITOR_VISUALIZATION + metaIN.VizUV = IN.vizUV; + metaIN.LightCoord = IN.lightCoord; + #endif + return UnityMetaFragment(metaIN); + } + ENDCG + + } + + + + + + } + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_Standard.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_Standard.txt.meta new file mode 100644 index 0000000..3ac06d6 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_Standard.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: d0469e88f445d184f88bc25be7464884 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_Standard.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2019.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2019.txt new file mode 100644 index 0000000..fb61079 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2019.txt @@ -0,0 +1,4834 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2019 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Opaque" "Queue" = "Geometry" } + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + + // Keywords + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE + #pragma multi_compile _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS _ADDITIONAL_OFF + #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile _ _SHADOWS_SOFT + #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE + + // GraphKeywords: + + + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define SHADER_PASS SHADERPASS_FORWARD + #define SHADERPASS_FORWARD + + #define _PASSFORWARD 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl" + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD19; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD9; + #endif + float4 fogFactorAndVertexLight : TEXCOORD10; + float4 shadowCoord : TEXCOORD11; + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if _PASSSHADOW + float3 _LightDirection; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + #if _PASSSHADOW + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, _LightDirection)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1, v.texcoord2, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD + OUTPUT_LIGHTMAP_UV(v.texcoord1, unity_LightmapST, o.lightmapUV); + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #if _BAKEDLIT + half3 vertexLight = 0; + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + #endif + half fogFactor = ComputeFogFactor(o.pos.z); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + + #ifdef _MAIN_LIGHT_SHADOWS + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if defined(_USESPECULAR) || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + InputData inputData; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + + #if !_UNLIT + #if _SIMPLELIT + half4 color = UniversalFragmentBlinnPhong( + inputData, + l.Albedo, + float4(specular * l.Smoothness, 0), + l.SpecularPower * 128, + l.Emission, + l.Alpha); + color.a = l.Alpha; + #elif _BAKEDLIT + half4 color = color = UniversalFragmentBakedLit(inputData, l.Albedo, l.Alpha, normalTS); + #else + half4 color = UniversalFragmentPBR( + inputData, + l.Albedo, + metallic, + specular, + l.Smoothness, + l.Occlusion, + l.Emission, + l.Alpha); + #endif + + #else + half4 color = half4(l.Albedo, l.Alpha); + #endif + + #if _UNLITFOG && !DISABLEFOG + color.rgb = MixFog(color.rgb, IN.fogFactorAndVertexLight.x); + #endif + + ChainFinalColorForward(l, d, color); + + return color; + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define SHADERPASS_SHADOWCASTER + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl" + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD19; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD9; + #endif + float4 fogFactorAndVertexLight : TEXCOORD10; + float4 shadowCoord : TEXCOORD11; + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if _PASSSHADOW + float3 _LightDirection; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + #if _PASSSHADOW + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, _LightDirection)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1, v.texcoord2, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD + OUTPUT_LIGHTMAP_UV(v.texcoord1, unity_LightmapST, o.lightmapUV); + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #if _BAKEDLIT + half3 vertexLight = 0; + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + #endif + half fogFactor = ComputeFogFactor(o.pos.z); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + + #ifdef _MAIN_LIGHT_SHADOWS + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2019.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2019.txt.meta new file mode 100644 index 0000000..3fe7a13 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2019.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 3a9baa42d2bd0f2418209ef9ad138f0e +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2019.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2020.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2020.txt new file mode 100644 index 0000000..4e822ac --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2020.txt @@ -0,0 +1,4888 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2020 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Opaque" "UniversalMaterialType" = "Lit" "Queue" = "Geometry" } + + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Cull Back + Blend One Zero + ZTest LEqual + ZWrite On + + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + + // Keywords + #pragma multi_compile _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE + #pragma multi_compile _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS _ADDITIONAL_OFF + #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile _ _SHADOWS_SOFT + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + // GraphKeywords: + + #define SHADER_PASS SHADERPASS_FORWARD + #define SHADERPASS_FORWARD + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define _PASSFORWARD 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl" + + + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD19; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD9; + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + float4 fogFactorAndVertexLight : TEXCOORD10; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD11; + #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if _PASSSHADOW + float3 _LightDirection; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + #if _PASSSHADOW + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, _LightDirection)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, o.pos.w * UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, o.pos.w * UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #if _BAKEDLIT + half3 vertexLight = 0; + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + #endif + half fogFactor = ComputeFogFactor(o.pos.z); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if _USESPECULAR || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + + + InputData inputData; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos); + #if !_BAKEDLIT + inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector)); + inputData.shadowMask = mulColor; + #endif + #endif + + #if !_UNLIT + #if _SIMPLELIT + half4 color = UniversalFragmentBlinnPhong( + inputData, + l.Albedo, + float4(specular * l.Smoothness, 0), + l.SpecularPower * 128, + l.Emission, + l.Alpha); + color.a = l.Alpha; + #elif _BAKEDLIT + color = UniversalFragmentBakedLit(inputData, l.Albedo, l.Alpha, normalTS); + #else + + + SurfaceData surface = (SurfaceData)0; + surface.albedo = l.Albedo; + surface.metallic = saturate(metallic); + surface.specular = specular; + surface.smoothness = saturate(l.Smoothness), + surface.occlusion = l.Occlusion, + surface.emission = l.Emission, + surface.alpha = saturate(l.Alpha); + surface.clearCoatMask = 0; + surface.clearCoatSmoothness = 1; + + #ifdef _CLEARCOAT + surface.clearCoatMask = saturate(l.CoatMask); + surface.clearCoatSmoothness = saturate(l.CoatSmoothness); + #endif + + half4 color = UniversalFragmentPBR(inputData, surface); + + #endif + + #else + half4 color = half4(l.Albedo, l.Alpha); + + #endif + + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, IN.fogFactorAndVertexLight.x); + #endif + ChainFinalColorForward(l, d, color); + + return color; + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define SHADERPASS_SHADOWCASTER + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl" + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD12; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD19; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD9; + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + float4 fogFactorAndVertexLight : TEXCOORD10; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD11; + #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if _PASSSHADOW + float3 _LightDirection; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + + #if _PASSSHADOW + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, _LightDirection)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, o.pos.w * UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, o.pos.w * UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #if _BAKEDLIT + half3 vertexLight = 0; + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + #endif + half fogFactor = ComputeFogFactor(o.pos.z); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2020.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2020.txt.meta new file mode 100644 index 0000000..7d8eee2 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2020.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: aa67532b31576e249a3d2c13ec2c0cf8 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2020.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2021.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2021.txt new file mode 100644 index 0000000..94aa483 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2021.txt @@ -0,0 +1,4980 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2021 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0 + [HideInInspector]_QueueControl("_QueueControl", Float) = -1 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Opaque" "UniversalMaterialType" = "Lit" "Queue" = "Geometry" } + + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Cull Back + Blend One Zero + ZTest LEqual + ZWrite On + + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + + // Keywords + #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + #pragma multi_compile_fragment _ _SHADOWS_SOFT + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + //#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 + #pragma multi_compile_fragment _ _LIGHT_LAYERS + #pragma multi_compile_fragment _ DEBUG_DISPLAY + #pragma multi_compile_fragment _ _LIGHT_COOKIES + #pragma multi_compile _ _CLUSTERED_RENDERING + // GraphKeywords: + + #define SHADER_PASS SHADERPASS_FORWARD + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define _PASSFORWARD 1 + #define _FOG_FRAGMENT 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + + + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + +#if _UNLIT + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl" +#endif + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if _USESPECULAR || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + + + InputData inputData = (InputData)0; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + +#if _BAKEDLIT + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = 0; +#else + inputData.fogCoord = InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x); + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; +#endif + + + + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #elif _BAKEDLIT + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #else + #if defined(DYNAMICLIGHTMAP_ON) + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS); + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + #endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos); + #if !_BAKEDLIT + inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector)); + inputData.shadowMask = mulColor; + #endif + #else + inputData.shadowMask = float4(1,1,1,1); + #endif + + #if defined(DEBUG_DISPLAY) + #if defined(DYNAMICLIGHTMAP_ON) + inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy; + #endif + #if defined(LIGHTMAP_ON) + inputData.staticLightmapUV = IN.lightmapUV; + #else + inputData.vertexSH = IN.sh; + #endif + #endif + + #if _WORLDSPACENORMAL + float3 normalTS = WorldToTangentSpace(d, l.Normal); + #else + float3 normalTS = l.Normal; + #endif + + SurfaceData surface = (SurfaceData)0; + surface.albedo = l.Albedo; + surface.metallic = saturate(metallic); + surface.specular = specular; + surface.smoothness = saturate(l.Smoothness), + surface.occlusion = l.Occlusion, + surface.emission = l.Emission, + surface.alpha = saturate(l.Alpha); + surface.clearCoatMask = 0; + surface.clearCoatSmoothness = 1; + + #ifdef _CLEARCOAT + surface.clearCoatMask = saturate(l.CoatMask); + surface.clearCoatSmoothness = saturate(l.CoatSmoothness); + #endif + + #if !_UNLIT + half4 color = half4(l.Albedo, l.Alpha); + #ifdef _DBUFFER + #if _BAKEDLIT + half3 bakeColor = color.rgb; + float3 bakeNormal = inputData.normalWS.xyz; + ApplyDecalToBaseColorAndNormal(IN.pos, bakeColor, bakeNormal); + color.rgb = bakeColor; + inputData.normalWS.xyz = bakeNormal; + #else + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + #endif + #if _SIMPLELIT + color = UniversalFragmentBlinnPhong( + inputData, + surface); + #elif _BAKEDLIT + color = UniversalFragmentBakedLit(inputData, color.rgb, color.a, normalTS); + #else + color = UniversalFragmentPBR(inputData, surface); + #endif + + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + + #else // unlit + #ifdef _DBUFFER + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + half4 color = UniversalFragmentUnlit(inputData, l.Albedo, l.Alpha); + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + #endif + ChainFinalColorForward(l, d, color); + + return color; + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW + + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2021.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2021.txt.meta new file mode 100644 index 0000000..c5b7a10 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2021.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 69090a1deecc05842bc9e7d8d9f7ae6e +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2021.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2022.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2022.txt new file mode 100644 index 0000000..ef23cad --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2022.txt @@ -0,0 +1,5007 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2022 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0 + [HideInInspector]_QueueControl("_QueueControl", Float) = -1 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Opaque" "UniversalMaterialType" = "Lit" "Queue" = "Geometry" } + + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Cull Back + Blend One Zero + ZTest LEqual + ZWrite On + + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + #pragma multi_compile _ DOTS_INSTANCING_ON + + // Keywords + #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + #pragma multi_compile_fragment _ _SHADOWS_SOFT + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + //#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 + #pragma multi_compile_fragment _ _LIGHT_LAYERS + #pragma multi_compile_fragment _ DEBUG_DISPLAY + #pragma multi_compile_fragment _ _LIGHT_COOKIES + #pragma multi_compile_fragment _ _WRITE_RENDERING_LAYERS + #pragma multi_compile _ _FORWARD_PLUS + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + // GraphKeywords: + + #define SHADER_PASS SHADERPASS_FORWARD + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define _PASSFORWARD 1 + #define _FOG_FRAGMENT 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + +#if _UNLIT + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl" +#endif + + // fragment shader + void Frag (VertexToPixel IN + , out half4 outColor : SV_Target0 + #ifdef _WRITE_RENDERING_LAYERS + , out float4 outRenderingLayers : SV_Target1 + #endif + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if _USESPECULAR || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + + + InputData inputData = (InputData)0; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + +#if _BAKEDLIT + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = 0; +#else + inputData.fogCoord = InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x); + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; +#endif + + + + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #elif _BAKEDLIT + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #else + #if defined(DYNAMICLIGHTMAP_ON) + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS); + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + #endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos); + #if !_BAKEDLIT + inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector)); + inputData.shadowMask = mulColor; + #endif + #else + inputData.shadowMask = float4(1,1,1,1); + #endif + + #if defined(DEBUG_DISPLAY) + #if defined(DYNAMICLIGHTMAP_ON) + inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy; + #endif + #if defined(LIGHTMAP_ON) + inputData.staticLightmapUV = IN.lightmapUV; + #else + inputData.vertexSH = IN.sh; + #endif + #endif + + #if _WORLDSPACENORMAL + float3 normalTS = WorldToTangentSpace(d, l.Normal); + #else + float3 normalTS = l.Normal; + #endif + + SurfaceData surface = (SurfaceData)0; + surface.albedo = l.Albedo; + surface.metallic = saturate(metallic); + surface.specular = specular; + surface.smoothness = saturate(l.Smoothness), + surface.occlusion = l.Occlusion, + surface.emission = l.Emission, + surface.alpha = saturate(l.Alpha); + surface.clearCoatMask = 0; + surface.clearCoatSmoothness = 1; + + #ifdef _CLEARCOAT + surface.clearCoatMask = saturate(l.CoatMask); + surface.clearCoatSmoothness = saturate(l.CoatSmoothness); + #endif + + #if !_UNLIT + half4 color = half4(l.Albedo, l.Alpha); + #ifdef _DBUFFER + #if _BAKEDLIT + half3 bakeColor = color.rgb; + float3 bakeNormal = inputData.normalWS.xyz; + ApplyDecalToBaseColorAndNormal(IN.pos, bakeColor, bakeNormal); + color.rgb = bakeColor; + inputData.normalWS.xyz = bakeNormal; + #else + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + #endif + #if _SIMPLELIT + color = UniversalFragmentBlinnPhong( + inputData, + surface); + #elif _BAKEDLIT + color = UniversalFragmentBakedLit(inputData, color.rgb, color.a, normalTS); + #else + color = UniversalFragmentPBR(inputData, surface); + #endif + + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + + #else // unlit + #ifdef _DBUFFER + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + half4 color = UniversalFragmentUnlit(inputData, l.Albedo, l.Alpha); + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + #endif + ChainFinalColorForward(l, d, color); + + outColor = color; + + #ifdef _WRITE_RENDERING_LAYERS + #if UNITY_VERSION >= 60020000 + outRenderingLayers = EncodeMeshRenderingLayer(); + #else + uint renderingLayers = GetMeshRenderingLayer(); + outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0); + #endif + #endif + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + +#if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); +#endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = TransformObjectToWorld(v.vertex.xyz); + o.worldNormal = TransformObjectToWorldNormal(v.normal); + o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + OUTPUT_SH(o.worldNormal, o.sh); + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + } + + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2022.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2022.txt.meta new file mode 100644 index 0000000..c200830 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2022.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 7a76ffb960fb45246965a6e47eeb1a66 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2022.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2023.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2023.txt new file mode 100644 index 0000000..1c11695 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2023.txt @@ -0,0 +1,5258 @@ +//////////////////////////////////////// +// Generated with Better Shaders +// +// Auto-generated shader code, don't hand edit! +// +// Unity Version: 2021.3.45f2 +// Render Pipeline: URP2023 +// Platform: WindowsEditor +//////////////////////////////////////// + + +Shader "AllIn1SpriteShader/AllIn1SpriteShaderLit_BetterShader" +{ + Properties + { + + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "white" {} //0 + _Color("Main Color", Color) = (1,1,1,1) //1 + _Alpha("General Alpha", Range(0,1)) = 1 //2 + + _GlowColor("Glow Color", Color) = (1,1,1,1) //3 + _Glow("Glow Color Intensity", Range(0,100)) = 10 //4 + _GlowGlobal("Global Glow Intensity", Range(1,100)) = 1 //5 + [NoScaleOffset] _GlowTex("Glow Texture", 2D) = "white" {} //6 + + [NoScaleOffset] _FadeTex("Fade Texture", 2D) = "white" {} //7 + _FadeAmount("Fade Amount", Range(-0.1,1)) = -0.1 //8 + _FadeBurnWidth("Fade Burn Width", Range(0,1)) = 0.025 //9 + _FadeBurnTransition("Burn Transition", Range(0.01,0.5)) = 0.075 //10 + _FadeBurnColor("Fade Burn Color", Color) = (1,1,0,1) //11 + _FadeBurnTex("Fade Burn Texture", 2D) = "white" {} //12 + _FadeBurnGlow("Fade Burn Glow", Range(1,250)) = 2//13 + + _OutlineColor("Outline Base Color", Color) = (1,1,1,1) //14 + _OutlineAlpha("Outline Base Alpha", Range(0,1)) = 1 //15 + _OutlineGlow("Outline Base Glow", Range(1,100)) = 1.5 //16 + _OutlineWidth("Outline Base Width", Range(0,0.2)) = 0.004 //17 + _OutlinePixelWidth("Outline Base Pixel Width", Int) = 1 //18 + + [Space] + _OutlineTex("Outline Texture", 2D) = "white" {} //19 + _OutlineTexXSpeed("Texture scroll speed X", Range(-50,50)) = 10 //20 + _OutlineTexYSpeed("Texture scroll speed Y", Range(-50,50)) = 0 //21 + + [Space] + [NoScaleOffset] _OutlineDistortTex("Outline Distortion Texture", 2D) = "white" {} //22 + _OutlineDistortAmount("Outline Distortion Amount", Range(0,2)) = 0.5 //23 + _OutlineDistortTexXSpeed("Distortion scroll speed X", Range(-50,50)) = 5 //24 + _OutlineDistortTexYSpeed("Distortion scroll speed Y", Range(-50,50)) = 5 //25 + + _AlphaOutlineColor("Color", Color) = (1, 1, 1, 1) //26 + _AlphaOutlineGlow("Outline Glow", Range(1,100)) = 5 //27 + _AlphaOutlinePower("Power", Range(0, 5)) = 1 // 28 + _AlphaOutlineMinAlpha("Min Alpha", Range(0, 1)) = 0 // 29 + _AlphaOutlineBlend("Blend", Range(0, 1)) = 1 // 30 + + _GradBlend("Gradient Blend", Range(0,1)) = 1 //31 + _GradTopLeftCol("Top Color", Color) = (1,0,0,1) //32 + _GradTopRightCol("Top Color 2", Color) = (1, 1, 0, 1) //33 + _GradBotLeftCol("Bot Color", Color) = (0,0,1,1) //34 + _GradBotRightCol("Bot Color 2", Color) = (0, 1, 0, 1) //35 + + [NoScaleOffset] _ColorSwapTex("Color Swap Texture", 2D) = "black" {} //36 + [HDR] _ColorSwapRed("Red Channel", Color) = (1,1,1,1) //37 + _ColorSwapRedLuminosity("Red luminosity", Range(-1,1)) = 0.5 //38 + [HDR] _ColorSwapGreen("Green Channel", Color) = (1,1,1,1) //39 + _ColorSwapGreenLuminosity("Green luminosity", Range(-1,1)) = 0.5 //40 + [HDR] _ColorSwapBlue("Blue Channel", Color) = (1,1,1,1) //41 + _ColorSwapBlueLuminosity("Blue luminosity", Range(-1,1)) = 0.5 //42 + + _HsvShift("Hue Shift", Range(0, 360)) = 180 //43 + _HsvSaturation("Saturation", Range(0, 2)) = 1 //44 + _HsvBright("Brightness", Range(0, 2)) = 1 //45 + + _HitEffectColor("Hit Effect Color", Color) = (1,1,1,1) //46 + _HitEffectGlow("Glow Intensity", Range(1,100)) = 5 //47 + [Space] + _HitEffectBlend("Hit Effect Blend", Range(0,1)) = 1 //48 + + _NegativeAmount("Negative Amount", Range(0, 1)) = 1 //49 + + _PixelateSize("Pixelate size", Range(4,512)) = 32 //50 + + [NoScaleOffset] _ColorRampTex("Color ramp Texture", 2D) = "white" {} //51 + _ColorRampLuminosity("Color ramp luminosity", Range(-1,1)) = 0 //52 + [Toggle()] _ColorRampOutline("Affects everything?", float) = 0 //53 + + _GreyscaleLuminosity("Greyscale luminosity", Range(-1,1)) = 0 //54 + [Toggle()] _GreyscaleOutline("Affects everything?", float) = 0 //55 + _GreyscaleTintColor("Greyscale Tint Color", Color) = (1,1,1,1) //56 + + _PosterizeNumColors("Number of Colors", Range(0,100)) = 8 //57 + _PosterizeGamma("Posterize Amount", Range(0.1,10)) = 0.75 //58 + [Toggle()] _PosterizeOutline("Affects everything?", float) = 0 //59 + + _BlurIntensity("Blur Intensity", Range(0,100)) = 10 //60 + [Toggle()] _BlurHD("Blur is Low Res?", float) = 0 //61 + + _MotionBlurAngle("Motion Blur Angle", Range(-1, 1)) = 0.1 //62 + _MotionBlurDist("Motion Blur Distance", Range(-3, 3)) = 1.25 //63 + + _GhostColorBoost("Ghost Color Boost", Range(0,5)) = 1 //64 + _GhostTransparency("Ghost Transparency", Range(0,1)) = 0 //65 + + _InnerOutlineColor("Inner Outline Color", Color) = (1,0,0,1) //66 + _InnerOutlineThickness("Outline Thickness", Range(0,3)) = 1 //67 + _InnerOutlineAlpha("Inner Outline Alpha", Range(0,1)) = 1 //68 + _InnerOutlineGlow("Inner Outline Glow", Range(1,250)) = 4 //69 + + _AlphaCutoffValue("Alpha cutoff value", Range(0, 1)) = 0.25 //70 + + [Toggle()] _OnlyOutline("Only render outline?", float) = 0 //71 + [Toggle()] _OnlyInnerOutline("Only render inner outline?", float) = 0 //72 + + _HologramStripesAmount("Stripes Amount", Range(0, 1)) = 0.1 //73 + _HologramUnmodAmount("Unchanged Amount", Range(0, 1)) = 0.0 //74 + _HologramStripesSpeed("Stripes Speed", Range(-20, 20)) = 4.5 //75 + _HologramMinAlpha("Min Alpha", Range(0, 1)) = 0.1 //76 + _HologramMaxAlpha("Max Alpha", Range(0, 100)) = 0.75 //77 + + _ChromAberrAmount("ChromAberr Amount", Range(0, 1)) = 1 //78 + _ChromAberrAlpha("ChromAberr Alpha", Range(0, 1)) = 0.4 //79 + + _GlitchAmount("Glitch Amount", Range(0, 20)) = 3 //80 + + _FlickerPercent("Flicker Percent", Range(0, 1)) = 0.05 //81 + _FlickerFreq("Flicker Frequency", Range(0, 5)) = 0.2 //82 + _FlickerAlpha("Flicker Alpha", Range(0, 1)) = 0 //83 + + _ShadowX("Shadow X Axis", Range(-0.5, 0.5)) = 0.1 //84 + _ShadowY("Shadow Y Axis", Range(-0.5, 0.5)) = -0.05 //85 + _ShadowAlpha("Shadow Alpha", Range(0, 1)) = 0.5 //86 + _ShadowColor("Shadow Color", Color) = (0, 0, 0, 1) //87 + + _HandDrawnAmount("Hand Drawn Amount", Range(0, 20)) = 10 //88 + _HandDrawnSpeed("Hand Drawn Speed", Range(1, 15)) = 5 //89 + + _GrassSpeed("Speed", Range(0,50)) = 2 //90 + _GrassWind("Bend amount", Range(0,50)) = 20 //91 + [Space] + [Toggle()] _GrassManualToggle("Manually animated?", float) = 0 //92 + _GrassManualAnim("Manual Anim Value", Range(-1,1)) = 1 //93 + + _WaveAmount("Wave Amount", Range(0, 25)) = 7 //94 + _WaveSpeed("Wave Speed", Range(0, 25)) = 10 //95 + _WaveStrength("Wave Strength", Range(0, 25)) = 7.5 //96 + _WaveX("Wave X Axis", Range(0, 1)) = 0 //97 + _WaveY("Wave Y Axis", Range(0, 1)) = 0.5 //98 + + _RectSize("Rect Size", Range(1, 4)) = 1 //99 + + _OffsetUvX("X axis", Range(-1, 1)) = 0 //100 + _OffsetUvY("Y axis", Range(-1, 1)) = 0 //101 + + _ClipUvLeft("Clipping Left", Range(0, 1)) = 0 //102 + _ClipUvRight("Clipping Right", Range(0, 1)) = 0 //103 + _ClipUvUp("Clipping Up", Range(0, 1)) = 0 //104 + _ClipUvDown("Clipping Down", Range(0, 1)) = 0 //105 + + _TextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 1 //106 + _TextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0 //107 + + _ZoomUvAmount("Zoom Amount", Range(0.1, 5)) = 0.5 //108 + + [NoScaleOffset] _DistortTex("Distortion Texture", 2D) = "white" {} //109 + _DistortAmount("Distortion Amount", Range(0,2)) = 0.5 //110 + _DistortTexXSpeed("Scroll speed X", Range(-50,50)) = 5 //111 + _DistortTexYSpeed("Scroll speed Y", Range(-50,50)) = 5 //112 + + _TwistUvAmount("Twist Amount", Range(0, 3.1416)) = 1 //113 + _TwistUvPosX("Twist Pos X Axis", Range(0, 1)) = 0.5 //114 + _TwistUvPosY("Twist Pos Y Axis", Range(0, 1)) = 0.5 //115 + _TwistUvRadius("Twist Radius", Range(0, 3)) = 0.75 //116 + + _RotateUvAmount("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //117 + + _FishEyeUvAmount("Fish Eye Amount", Range(0, 0.5)) = 0.35 //118 + + _PinchUvAmount("Pinch Amount", Range(0, 0.5)) = 0.35 //119 + + _ShakeUvSpeed("Shake Speed", Range(0, 20)) = 2.5 //120 + _ShakeUvX("X Multiplier", Range(0, 5)) = 1.5 //121 + _ShakeUvY("Y Multiplier", Range(0, 5)) = 1 //122 + + _ColorChangeTolerance("Tolerance", Range(0, 1)) = 0.25 //123 + _ColorChangeTarget("Color to change", Color) = (1, 0, 0, 1) //124 + [HDR] _ColorChangeNewCol("New Color", Color) = (1, 1, 0, 1) //125 + _ColorChangeLuminosity("New Color Luminosity", Range(0, 1)) = 0.0 //126 + + _RoundWaveStrength("Wave Strength", Range(0, 1)) = 0.7 //127 + _RoundWaveSpeed("Wave Speed", Range(0, 5)) = 2 //128 + + [Toggle()] _BillboardY("Billboard on both axis?", float) = 0 //129 + _ZWrite ("Depth Write", Float) = 1.0 // 130 + + _MySrcMode ("SrcMode", Float) = 5 // 131 + _MyDstMode ("DstMode", Float) = 10 // 132 + + _ShineColor("Shine Color", Color) = (1,1,1,1) // 133 + _ShineLocation("Shine Location", Range(0,1)) = 0.5 // 134 + _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0 //135 + _ShineWidth("Shine Width", Range(0.05,1)) = 0.1 // 136 + _ShineGlow("Shine Glow", Range(0,100)) = 1 // 137 + [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {} // 138 + + _GlitchSize("Glitch Size", Range(0.25, 5)) = 1 //139 + _HologramStripeColor("Stripes Color", Color) = (0,1,1,1) //140 + _GradBoostX("Boost X axis", Range(0.1, 5)) = 1.2 //141 + _GradBoostY("Boost Y axis", Range(0.1, 5)) = 1.2 //142 + [Toggle()] _GradIsRadial("Radial Gradient?", float) = 0 //143 + _AlphaRoundThreshold("Round Threshold", Range(0.005, 1.0)) = 0.5 //144 + _GrassRadialBend("Radial Bend", Range(0.0, 5.0)) = 0.1 //145 + + _ColorChangeTolerance2("Tolerance 2", Range(0, 1)) = 0.25 //146 + _ColorChangeTarget2("Color to change 2", Color) = (1, 0, 0, 1) //147 + [HDR] _ColorChangeNewCol2("New Color 2", Color) = (1, 1, 0, 1) //148 + _ColorChangeTolerance3("Tolerance 3", Range(0, 1)) = 0.25 //149 + _ColorChangeTarget3("Color to change 3", Color) = (1, 0, 0, 1) //150 + [HDR] _ColorChangeNewCol3("New Color 3", Color) = (1, 1, 0, 1) //151 + + _Contrast ("Contrast", Range(0, 6)) = 1 // 152 + _Brightness ("Brightness", Range(-1, 1)) = 0 // 153 + + _ColorSwapBlend ("Color Swap Blend", Range(0, 1)) = 1 // 154 + _ColorRampBlend ("Color Ramp Blend", Range(0, 1)) = 1 // 155 + _GreyscaleBlend ("Greyscale Blend", Range(0, 1)) = 1 // 156 + _GhostBlend ("Ghost Blend", Range(0, 1)) = 1 // 157 + _HologramBlend ("Hologram Blend", Range(0, 1)) = 1 // 158 + + [NoScaleOffset] [AllIn1ShaderGradient] _ColorRampTexGradient("Color ramp Gradient", 2D) = "white" {} //159 + + [NoScaleOffset] _OverlayTex("Overlay Texture", 2D) = "white" {} //160 + _OverlayColor("Overlay Color", Color) = (1, 1, 1, 1) //161 + _OverlayGlow("Overlay Glow", Range(0,25)) = 1 // 162 + _OverlayBlend("Overlay Blend", Range(0, 1)) = 1 // 163 + + _RadialStartAngle("Radial Start Angle", Range(0, 360)) = 90 //164 + _RadialClip("Radial Clip", Range(0, 360)) = 45 //165 + _RadialClip2("Radial Clip 2", Range(0, 360)) = 0 //166 + + _WarpStrength("Warp Strength", Range(0, 0.1)) = 0.025 //167 + _WarpSpeed("Warp Speed", Range(0, 25)) = 8 //168 + _WarpScale("Warp Scale", Range(0.05, 3)) = 0.5 //169 + + _OverlayTextureScrollXSpeed("Speed X Axis", Range(-5, 5)) = 0.25 //170 + _OverlayTextureScrollYSpeed("Speed Y Axis", Range(-5, 5)) = 0.25 //171 + + /**/ + _MainTex_ScaleAndTiling("Main Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //172 + _FadeTex_ScaleAndTiling("Fade Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //173 + _FadeBurnTex_ScaleAndTiling("Fade Burn Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //174 + _OutlineTex_ScaleAndTiling("Outline Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //175 + _OutlineDistortTex_ScaleAndTiling("Outline Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //176 + _DistortTex_ScaleAndTiling("Distort Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //177 + _OverlayTex_ScaleAndTiling("Overlay Tex - Scale and Tiling", Vector) = (1, 1, 0, 0) //178 + [HideInInspector]_SpriteFlip("_SpriteFlip", Vector) = (1, 1, 1, 1) //179 + /**/ + + _GlitchSpeed("Glitch Speed", Range(0.0, 100)) = 20 //180 + + _ZTestMode ("Z Test Mode", Float) = 4 //181 + _CullingOption ("Culling Option", float) = 0 //182 + + [HideInInspector] _MinXUV("_MinXUV", Range(0, 1)) = 0.0 //183 + [HideInInspector] _MaxXUV("_MaxXUV", Range(0, 1)) = 1.0 //184 + [HideInInspector] _MinYUV("_MinYUV", Range(0, 1)) = 0.0 //185 + [HideInInspector] _MaxYUV("_MaxYUV", Range(0, 1)) = 1.0 //186 + [HideInInspector] _RandomSeed("_MaxYUV", Range(0, 10000)) = 0.0 //187 + _EditorDrawers("Editor Drawers", Int) = 6 //188 + + [Normal][NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {} //189 + _NormalStrength("Normal Strength", Range(0, 15)) = 1.0 //190 + + + [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0 + [HideInInspector]_QueueControl("_QueueControl", Float) = -1 + [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {} + [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {} + + } + SubShader + { + Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Opaque" "UniversalMaterialType" = "Lit" "Queue" = "Geometry" } + + + + + Pass + { + Name "Universal Forward" + Tags + { + "LightMode" = "UniversalForward" + } + Cull Back + Blend One Zero + ZTest LEqual + ZWrite On + + Blend One Zero, One Zero +Cull Back +ZTest LEqual +ZWrite On + + Blend [_MySrcMode] [_MyDstMode] + Cull [_CullingOption] + ZWrite [_ZWrite] + ZTest [_ZTestMode] + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_fog + #pragma multi_compile_instancing + #pragma instancing_options renderinglayer + + // Keywords + #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile _ DYNAMICLIGHTMAP_ON + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + #pragma multi_compile_fragment _ _SHADOWS_SOFT + #pragma multi_compile_fragment _ _SHADOWS_SOFT_LOW + #pragma multi_compile_fragment _ _SHADOWS_SOFT_MEDIUM + #pragma multi_compile_fragment _ _SHADOWS_SOFT_HIGH + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + //#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 + #pragma multi_compile_fragment _ _LIGHT_LAYERS + #pragma multi_compile_fragment _ DEBUG_DISPLAY + #pragma multi_compile_fragment _ _LIGHT_COOKIES + #pragma multi_compile _ _FORWARD_PLUS + #pragma multi_compile _ EVALUATE_SH_VERTEX + #pragma multi_compile _ EVALUATE_SH_MIXED + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + + // GraphKeywords: + + #define SHADER_PASS SHADERPASS_FORWARD + #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + #define _PASSFORWARD 1 + #define _FOG_FRAGMENT 1 + + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + // this has to be here or specular color will be ignored. Not in SG code + #if _SIMPLELIT + #define _SPECULAR_COLOR + #endif + + + // Includes + + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float4 probeOcclusion : TEXCOORD8; + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float4 previousPositionCS : TEXCOORD21; // Contain previous transform position (in case of skinning for example) + float4 positionCS : TEXCOORD22; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #define GetWorldToViewMatrix() _ViewMatrix + #define UNITY_MATRIX_I_V _InvViewMatrix + #define GetViewToHClipMatrix() OptimizeProjectionMatrix(_ProjMatrix) + #define UNITY_MATRIX_I_P _InvProjMatrix + #define GetWorldToHClipMatrix() _ViewProjMatrix + #define UNITY_MATRIX_I_VP _InvViewProjMatrix + #define UNITY_MATRIX_UNJITTERED_VP _NonJitteredViewProjMatrix + #define UNITY_MATRIX_PREV_VP _PrevViewProjMatrix + #define UNITY_MATRIX_PREV_I_VP _PrevInvViewProjMatrix + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = v; + #endif + #if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); + #endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // This return the camera relative position (if enable) + float3 positionWS = TransformObjectToWorld(v.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(v.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = positionWS; + o.worldNormal = normalWS; + o.worldTangent = tangentWS; + + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + #if UNITY_VERSION < 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #if UNITY_VERSION >= 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + #elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && UNITY_VERSION >= 60000009 + OUTPUT_SH4(vertexInput.positionWS, o.worldNormal.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), o.sh, o.probeOcclusion); + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(o); + #endif + + o.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + if (!forceNoMotion) + { + #if defined(HAVE_VFX_MODIFICATION) + float3 previousPositionOS = currentFrameMvData.vfxParticlePositionOS; + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + const bool applyDeformation = false; + #else + const bool applyDeformation = true; + #endif + #else + const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation + float3 previousPositionOS = hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz; + + #if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT) + const bool applyDeformation = true; + #else + const bool applyDeformation = hasDeformation; + #endif + #endif + // TODO + #if defined(FEATURES_GRAPH_VERTEX) + if (applyDeformation) + previousPositionOS = GetLastFrameDeformedPosition(previousMesh, currentFrameMvData, previousPositionOS); + else + previousPositionOS = previousMesh.positionOS; + + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + #endif + + #if defined(UNITY_DOTS_INSTANCING_ENABLED) && defined(DOTS_DEFORMED) + // Deformed vertices in DOTS are not cumulative with built-in Unity skinning/blend shapes + // Needs to be called after vertex modification has been applied otherwise it will be + // overwritten by Compute Deform node + ApplyPreviousFrameDeformedVertexPosition(previousMesh.vertexID, previousPositionOS); + #endif + #if defined (_ADD_PRECOMPUTED_VELOCITY) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + o.positionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionWS, 1.0f)); + + #if defined(HAVE_VFX_MODIFICATION) + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) || defined(_ADD_PRECOMPUTED_VELOCITY) + #error Unexpected fast path rendering VFX motion vector while there are vertex modification afterwards. + #endif + o.previousPositionCS = VFXGetPreviousClipPosition(previousMesh, currentFrameMvData.vfxElementAttributes, o.positionCS); + #else + #if VFX_WORLD_SPACE + //previousPositionOS is already in world space + const float3 previousPositionWS = previousPositionOS; + #else + const float3 previousPositionWS = mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f)).xyz; + #endif + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionWS, 1.0f)); + #endif + #else + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1))); + #endif + } + #endif + + return o; + } + + + + +#if _UNLIT + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl" +#endif + + // fragment shader + void Frag (VertexToPixel IN + , out half4 outColor : SV_Target0 + #ifdef _WRITE_RENDERING_LAYERS + , out float4 outRenderingLayers : SV_Target1 + #endif + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) + { + UNITY_SETUP_INSTANCE_ID(IN); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + #if _USESPECULAR || _SIMPLELIT + float3 specular = l.Specular; + float metallic = 1; + #else + float3 specular = 0; + float metallic = l.Metallic; + #endif + + + + + InputData inputData = (InputData)0; + + inputData.positionWS = IN.worldPos; + #if _WORLDSPACENORMAL + inputData.normalWS = l.Normal; + #else + inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal)); + #endif + + inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir); + + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + inputData.shadowCoord = IN.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos); + #else + inputData.shadowCoord = float4(0, 0, 0, 0); + #endif + +#if _BAKEDLIT + inputData.fogCoord = IN.fogFactorAndVertexLight.x; + inputData.vertexLighting = 0; +#else + inputData.fogCoord = InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x); + inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; +#endif + + + + #if defined(_OVERRIDE_BAKEDGI) + inputData.bakedGI = l.DiffuseGI; + l.Emission += l.SpecularGI; + #elif _BAKEDLIT + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #else + #if defined(DYNAMICLIGHTMAP_ON) + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS); + #elif defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2) + #if UNITY_VERSION >= 60000009 + inputData.bakedGI = SAMPLE_GI(IN.sh, IN.worldPos, inputData.normalWS, inputData.viewDirectionWS, IN.pos, IN.probeOcclusion, inputData.shadowMask); + #else + inputData.bakedGI = SAMPLE_GI(IN.sh, IN.worldPos, inputData.normalWS, inputData.viewDirectionWS, IN.pos); + #endif + #else + inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS); + #endif + #endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos); + #if !_BAKEDLIT + inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV); + + #if defined(_OVERRIDE_SHADOWMASK) + float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector)); + inputData.shadowMask = mulColor; + #endif + #else + inputData.shadowMask = float4(1,1,1,1); + #endif + + #if defined(DEBUG_DISPLAY) + #if defined(DYNAMICLIGHTMAP_ON) + inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy; + #endif + #if defined(LIGHTMAP_ON) + inputData.staticLightmapUV = IN.lightmapUV; + #else + inputData.vertexSH = IN.sh; + #endif + #endif + + #if _WORLDSPACENORMAL + float3 normalTS = WorldToTangentSpace(d, l.Normal); + #else + float3 normalTS = l.Normal; + #endif + + SurfaceData surface = (SurfaceData)0; + surface.albedo = l.Albedo; + surface.metallic = saturate(metallic); + surface.specular = specular; + surface.smoothness = saturate(l.Smoothness), + surface.occlusion = l.Occlusion, + surface.emission = l.Emission, + surface.alpha = saturate(l.Alpha); + surface.clearCoatMask = 0; + surface.clearCoatSmoothness = 1; + + #ifdef _CLEARCOAT + surface.clearCoatMask = saturate(l.CoatMask); + surface.clearCoatSmoothness = saturate(l.CoatSmoothness); + #endif + + #if !_UNLIT + half4 color = half4(l.Albedo, l.Alpha); + #ifdef _DBUFFER + #if _BAKEDLIT + half3 bakeColor = color.rgb; + float3 bakeNormal = inputData.normalWS.xyz; + ApplyDecalToBaseColorAndNormal(IN.pos, bakeColor, bakeNormal); + color.rgb = bakeColor; + inputData.normalWS.xyz = bakeNormal; + #else + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + #endif + #if _SIMPLELIT + color = UniversalFragmentBlinnPhong( + inputData, + surface); + #elif _BAKEDLIT + color = UniversalFragmentBakedLit(inputData, color.rgb, color.a, normalTS); + #else + color = UniversalFragmentPBR(inputData, surface); + #endif + + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + + #else // unlit + #ifdef _DBUFFER + ApplyDecalToSurfaceData(IN.pos, surface, inputData); + #endif + half4 color = UniversalFragmentUnlit(inputData, l.Albedo, l.Alpha); + #if !DISABLEFOG + color.rgb = MixFog(color.rgb, inputData.fogCoord); + #endif + #endif + ChainFinalColorForward(l, d, color); + + outColor = color; + + #ifdef _WRITE_RENDERING_LAYERS + #if UNITY_VERSION >= 60020000 + outRenderingLayers = EncodeMeshRenderingLayer(); + #else + uint renderingLayers = GetMeshRenderingLayer(); + outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0); + #endif + #endif + + } + + ENDHLSL + + } + + + + Pass + { + Name "ShadowCaster" + Tags + { + "LightMode" = "ShadowCaster" + } + + // Render State + Blend One Zero, One Zero + Cull Back + ZTest LEqual + ZWrite On + // ColorMask: + + + + HLSLPROGRAM + + #pragma vertex Vert + #pragma fragment Frag + + #pragma target 3.0 + + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma multi_compile_instancing + + #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW + #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE + + #define _NORMAL_DROPOFF_TS 1 + #define ATTRIBUTES_NEED_NORMAL + #define ATTRIBUTES_NEED_TANGENT + #define _PASSSHADOW 1 + + + #pragma shader_feature_local GLOW_ON + #pragma shader_feature_local FADE_ON + #pragma shader_feature_local OUTBASE_ON + #pragma shader_feature_local ONLYOUTLINE_ON + #pragma shader_feature_local GRADIENT_ON + #pragma shader_feature_local GRADIENT2COL_ON + #pragma shader_feature_local RADIALGRADIENT_ON + #pragma shader_feature_local COLORSWAP_ON + #pragma shader_feature_local HSV_ON + #pragma shader_feature_local CHANGECOLOR_ON + #pragma shader_feature_local CHANGECOLOR2_ON + #pragma shader_feature_local CHANGECOLOR3_ON + #pragma shader_feature_local COLORRAMP_ON + #pragma shader_feature_local GRADIENTCOLORRAMP_ON + #pragma shader_feature_local HITEFFECT_ON + #pragma shader_feature_local NEGATIVE_ON + #pragma shader_feature_local PIXELATE_ON + #pragma shader_feature_local GREYSCALE_ON + #pragma shader_feature_local POSTERIZE_ON + #pragma shader_feature_local BLUR_ON + #pragma shader_feature_local MOTIONBLUR_ON + #pragma shader_feature_local GHOST_ON + #pragma shader_feature_local ALPHAOUTLINE_ON + #pragma shader_feature_local INNEROUTLINE_ON + #pragma shader_feature_local ONLYINNEROUTLINE_ON + #pragma shader_feature_local HOLOGRAM_ON + #pragma shader_feature_local CHROMABERR_ON + #pragma shader_feature_local GLITCH_ON + #pragma shader_feature_local FLICKER_ON + #pragma shader_feature_local SHADOW_ON + #pragma shader_feature_local SHINE_ON + #pragma shader_feature_local CONTRAST_ON + #pragma shader_feature_local OVERLAY_ON + #pragma shader_feature_local OVERLAYMULT_ON + #pragma shader_feature_local DOODLE_ON + #pragma shader_feature_local WIND_ON + #pragma shader_feature_local WAVEUV_ON + #pragma shader_feature_local ROUNDWAVEUV_ON + #pragma shader_feature_local RECTSIZE_ON + #pragma shader_feature_local OFFSETUV_ON + #pragma shader_feature_local CLIPPING_ON + #pragma shader_feature_local RADIALCLIPPING_ON + #pragma shader_feature_local TEXTURESCROLL_ON + #pragma shader_feature_local ZOOMUV_ON + #pragma shader_feature_local DISTORT_ON + #pragma shader_feature_local WARP_ON + #pragma shader_feature_local TWISTUV_ON + #pragma shader_feature_local ROTATEUV_ON + #pragma shader_feature_local POLARUV_ON + #pragma shader_feature_local FISHEYE_ON + #pragma shader_feature_local PINCH_ON + #pragma shader_feature_local SHAKEUV_ON + + #pragma shader_feature_local GLOWTEX_ON + #pragma shader_feature_local OUTTEX_ON + #pragma shader_feature_local OUTDIST_ON + #pragma shader_feature_local OUTBASE8DIR_ON + #pragma shader_feature_local OUTBASEPIXELPERF_ON + #pragma shader_feature_local COLORRAMPOUTLINE_ON + #pragma shader_feature_local GREYSCALEOUTLINE_ON + #pragma shader_feature_local POSTERIZEOUTLINE_ON + #pragma shader_feature_local BLURISHD_ON + #pragma shader_feature_local MANUALWIND_ON + #pragma shader_feature_local ATLAS_ON + #pragma shader_feature_local PREMULTIPLYALPHA_ON + + #pragma shader_feature BILBOARD_ON + #pragma shader_feature BILBOARDY_ON + + #pragma shader_feature NORMALMAP_ON + + + #define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw + #define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb + + + + + + #define _URP 1 +#define _USINGTEXCOORD1 1 +#define _USINGTEXCOORD2 1 +#define NEED_FACING 1 + + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" + #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" + + #undef WorldNormalVector + #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix) + + #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal) + + #define _WorldSpaceLightPos0 _MainLightPosition + + #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name); + #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name); + #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name); + + #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z) + #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod) + #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord) + #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord) + + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod) + + #if defined(UNITY_COMPILER_HLSL) + #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0; + #else + #define UNITY_INITIALIZE_OUTPUT(type,name) + #endif + + #define sampler2D_float sampler2D + #define sampler2D_half sampler2D + + + + // data across stages, stripped like the above. + struct VertexToPixel + { + float4 pos : SV_POSITION; + float3 worldPos : TEXCOORD0; + float3 worldNormal : TEXCOORD1; + float4 worldTangent : TEXCOORD2; + float4 texcoord0 : TEXCOORD3; + float4 texcoord1 : TEXCOORD4; + float4 texcoord2 : TEXCOORD5; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD6; + // #endif + + // #if %SCREENPOSREQUIREKEY% + // float4 screenPos : TEXCOORD7; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + half4 vertexColor : COLOR; + // #endif + + #if defined(LIGHTMAP_ON) + float2 lightmapUV : TEXCOORD8; + #endif + #if defined(DYNAMICLIGHTMAP_ON) + float2 dynamicLightmapUV : TEXCOORD9; + #endif + #if !defined(LIGHTMAP_ON) + float4 probeOcclusion : TEXCOORD8; + float3 sh : TEXCOORD10; + #endif + + #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT) + float4 fogFactorAndVertexLight : TEXCOORD11; + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord : TEXCOORD12; + #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD13; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD14; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD15; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD16; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD17; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD18; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD19; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD20; + // #endif + + #if UNITY_ANY_INSTANCING_ENABLED + uint instanceID : CUSTOM_INSTANCE_ID; + #endif + #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE))) + uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0; + #endif + #if (defined(UNITY_STEREO_INSTANCING_ENABLED)) + uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex; + #endif + #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE) + FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC; + #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float4 previousPositionCS : TEXCOORD21; // Contain previous transform position (in case of skinning for example) + float4 positionCS : TEXCOORD22; + #endif + }; + + + + + // data describing the user output of a pixel + struct Surface + { + half3 Albedo; + half Height; + half3 Normal; + half Smoothness; + half3 Emission; + half Metallic; + half3 Specular; + half Occlusion; + half SpecularPower; // for simple lighting + half Alpha; + float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value + // HDRP Only + half SpecularOcclusion; + half SubsurfaceMask; + half Thickness; + half CoatMask; + half CoatSmoothness; + half Anisotropy; + half IridescenceMask; + half IridescenceThickness; + int DiffusionProfileHash; + float SpecularAAThreshold; + float SpecularAAScreenSpaceVariance; + // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines + float3 DiffuseGI; + float3 BackDiffuseGI; + float3 SpecularGI; + float ior; + float3 transmittanceColor; + float atDistance; + float transmittanceMask; + // requires _OVERRIDE_SHADOWMASK to be defines + float4 ShadowMask; + + // for decals + float NormalAlpha; + float MAOSAlpha; + + + }; + + // Data the user declares in blackboard blocks + struct Blackboard + { + + float blackboardDummyData; + }; + + // data the user might need, this will grow to be big. But easy to strip + struct ShaderData + { + float4 clipPos; // SV_POSITION + float3 localSpacePosition; + float3 localSpaceNormal; + float3 localSpaceTangent; + + float3 worldSpacePosition; + float3 worldSpaceNormal; + float3 worldSpaceTangent; + float tangentSign; + + float3 worldSpaceViewDir; + float3 tangentSpaceViewDir; + + float4 texcoord0; + float4 texcoord1; + float4 texcoord2; + float4 texcoord3; + + float2 screenUV; + float4 screenPos; + + float4 vertexColor; + bool isFrontFace; + + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + + float3x3 TBNMatrix; + Blackboard blackboard; + }; + + struct VertexData + { + #if SHADER_TARGET > 30 + // uint vertexID : SV_VertexID; + #endif + float4 vertex : POSITION; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + + // optimize out mesh coords when not in use by user or lighting system + #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER) + float4 texcoord1 : TEXCOORD1; + #endif + + #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON))) + float4 texcoord1 : TEXCOORD1; + #endif + #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON))) + float4 texcoord2 : TEXCOORD2; + #endif + + + #if _HDRP + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + #endif + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side). + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct TessVertex + { + float4 vertex : INTERNALTESSPOS; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 texcoord0 : TEXCOORD0; + float4 texcoord1 : TEXCOORD1; + float4 texcoord2 : TEXCOORD2; + + // #if %TEXCOORD3REQUIREKEY% + float4 texcoord3 : TEXCOORD3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + float4 vertexColor : COLOR; + // #endif + + // #if %EXTRAV2F0REQUIREKEY% + // float4 extraV2F0 : TEXCOORD5; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // float4 extraV2F1 : TEXCOORD6; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // float4 extraV2F2 : TEXCOORD7; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // float4 extraV2F3 : TEXCOORD8; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // float4 extraV2F4 : TEXCOORD9; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // float4 extraV2F5 : TEXCOORD10; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // float4 extraV2F6 : TEXCOORD11; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // float4 extraV2F7 : TEXCOORD12; + // #endif + + #if _PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)) + float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example) + #if defined (_ADD_PRECOMPUTED_VELOCITY) + float3 precomputedVelocity : TEXCOORD14; + #endif + #endif + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO + }; + + struct ExtraV2F + { + float4 extraV2F0; + float4 extraV2F1; + float4 extraV2F2; + float4 extraV2F3; + float4 extraV2F4; + float4 extraV2F5; + float4 extraV2F6; + float4 extraV2F7; + Blackboard blackboard; + float4 time; + }; + + + float3 WorldToTangentSpace(ShaderData d, float3 normal) + { + return mul(d.TBNMatrix, normal); + } + + float3 TangentToWorldSpace(ShaderData d, float3 normal) + { + return mul(normal, d.TBNMatrix); + } + + // in this case, make standard more like SRPs, because we can't fix + // unity_WorldToObject in HDRP, since it already does macro-fu there + + #if _STANDARD + float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); }; + float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); }; + float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); }; + float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); }; + float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; } + float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; } + #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER)) + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod) + #else + #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod) + #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod) + #endif + + #undef GetWorldToObjectMatrix() + + #define GetWorldToObjectMatrix() unity_WorldToObject + + + #endif + + float3 GetCameraWorldPosition() + { + #if _HDRP + return GetCameraRelativePositionWS(_WorldSpaceCameraPos); + #else + return _WorldSpaceCameraPos; + #endif + } + + #if _GRABPASSUSED + #if _STANDARD + TEXTURE2D(%GRABTEXTURE%); + SAMPLER(sampler_%GRABTEXTURE%); + #endif + + half3 GetSceneColor(float2 uv) + { + #if _STANDARD + return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb; + #else + return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv); + #endif + } + #endif + + + + #if _STANDARD + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); + float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); } + #else + float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); } + float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); } + float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); } + #endif + + float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir) + { + float eye = GetLinearEyeDepth(uv); + float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz); + + float dt = dot(worldSpaceViewDir, camView); + float3 div = worldSpaceViewDir/dt; + float3 wpos = (eye * div) + GetCameraWorldPosition(); + return wpos; + } + + #if _HDRP + float3 ObjectToWorldSpacePosition(float3 pos) + { + return GetAbsolutePositionWS(TransformObjectToWorld(pos)); + } + #else + float3 ObjectToWorldSpacePosition(float3 pos) + { + return TransformObjectToWorld(pos); + } + #endif + + #if _STANDARD + UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture); + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv); + float3 norms = DecodeViewNormalStereo(depthNorms); + norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5; + return norms; + } + #elif _HDRP && !_DECALSHADER + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + NormalData nd; + DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd); + return nd.normalWS; + } + #elif _URP + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl" + #endif + + float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir) + { + #if (SHADER_LIBRARY_VERSION_MAJOR >= 10) + return SampleSceneNormals(uv); + #else + float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir); + return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5; + #endif + + } + #endif + + #if _HDRP + + half3 UnpackNormalmapRGorAG(half4 packednormal) + { + // This do the trick + packednormal.x *= packednormal.w; + + half3 normal; + normal.xy = packednormal.xy * 2 - 1; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + half3 UnpackNormal(half4 packednormal) + { + #if defined(UNITY_NO_DXT5nm) + return packednormal.xyz * 2 - 1; + #else + return UnpackNormalmapRGorAG(packednormal); + #endif + } + #endif + #if _HDRP || _URP + + half3 UnpackScaleNormal(half4 packednormal, half scale) + { + #ifndef UNITY_NO_DXT5nm + // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1) + // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5 + packednormal.x *= packednormal.w; + #endif + half3 normal; + normal.xy = (packednormal.xy * 2 - 1) * scale; + normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); + return normal; + } + + #endif + + + void GetSun(out float3 lightDir, out float3 color) + { + lightDir = float3(0.5, 0.5, 0); + color = 1; + #if _HDRP + if (_DirectionalLightCount > 0) + { + DirectionalLightData light = _DirectionalLightDatas[0]; + lightDir = -light.forward.xyz; + color = light.color; + } + #elif _STANDARD + lightDir = normalize(_WorldSpaceLightPos0.xyz); + color = _LightColor0.rgb; + #elif _URP + Light light = GetMainLight(); + lightDir = light.direction; + color = light.color; + #endif + } + + + + CBUFFER_START(UnityPerMaterial) + + + float4 _SpriteFlip; + + half4 _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha, _AlphaCutoffValue; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + half _HsvShift, _HsvSaturation, _HsvBright; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half4 _FadeBurnColor/*, _FadeTex_ST, _FadeBurnTex_ST*/; + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition,_FadeBurnGlow; + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + + half _ColorRampLuminosity, _ColorRampBlend; + + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + + half _NegativeAmount; + + + half _PixelateSize; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _Contrast, _Brightness; + + half4 /*_OverlayTex_ST,*/ _OverlayColor; + float4 _OverlayTex_ScaleAndTiling; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + + half _RoundWaveStrength, _RoundWaveSpeed; + + + half _RectSize; + + + half _OffsetUvX, _OffsetUvY; + + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half _ZoomUvAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + half _NormalStrength; + + float _RandomSeed; + + + + + CBUFFER_END + + + + + + + + TEXTURE2D(_MainTex); + SAMPLER(sampler_MainTex); + + #if GLOW_ON + TEXTURE2D(_GlowTex); + SAMPLER(sampler_GlowTex); + #endif + + #if FADE_ON + TEXTURE2D(_FadeTex); + SAMPLER(sampler_FadeTex); + + TEXTURE2D(_FadeBurnTex); + SAMPLER(sampler_FadeBurnTex); + #endif + + #if DISTORT_ON + TEXTURE2D(_DistortTex); + SAMPLER(sampler_DistortTex); + #endif + + #if OUTTEX_ON + TEXTURE2D(_OutlineTex); + SAMPLER(sampler_OutlineTex); + #endif + + #if OUTDIST_ON + TEXTURE2D(_OutlineDistortTex); + SAMPLER(sampler_OutlineDistortTex); + #endif + + #if COLORSWAP_ON + TEXTURE2D(_ColorSwapTex); + SAMPLER(sampler_ColorSwapTex); + #endif + + #if COLORRAMP_ON + TEXTURE2D(_ColorRampTex); + TEXTURE2D(_ColorRampTexGradient); + SAMPLER(sampler_ColorRampTex); + SAMPLER(sampler_ColorRampTexGradient); + #endif + + #if SHINE_ON + TEXTURE2D(_ShineMask); + SAMPLER(sampler_ShineMask); + #endif + + #if OVERLAY_ON + TEXTURE2D(_OverlayTex); + SAMPLER(sampler_OverlayTex); + #endif + + #if NORMALMAP_ON + TEXTURE2D(_NormalMap); + SAMPLER(sampler_NormalMap); + #endif + + //BLURS------------------------------------------------------------------------- + half4 Blur(half2 uv, Texture2D source, SamplerState sampler_source, half Intensity) + { + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, sampler_source, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, sampler_source, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; + } + + half BlurHD_G(half bhqp, half x) + { + return exp(-(x * x) / (2.0 * bhqp * bhqp)); + } + half4 BlurHD(half2 uv, Texture2D source, SamplerState sampler_source, half BlurAmount, half xScale, half yScale) + { + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, sampler_source, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; + } + //----------------------------------------------------------------------- + + + //------------------------------------------- + half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); + } + //------------------------------------------- + + //----------------------------------------------------------------------- + half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; + } + + half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; + } + //----------------------------------------------------------------------- + + + void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F d) + { + //BILBOARD_ON + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + float3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + v.vertex = float4(localPos, 1); + #else + float3 localPos = v.vertex.xyz; + v.vertex = float4(localPos, 1.0); + #endif + //----------------------------------------------------------- + + v.texcoord0.xy = v.texcoord0.xy * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + //POLARUV_ON + #if POLARUV_ON + v.texcoord0.xy = v.texcoord0.xy - center; + #endif + + //---------------------------------------- + + //ROTATEUV_ON + #if ROTATEUV_ON + half2 uvC = v.texcoord0.xy; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + v.texcoord0.xy = mul(rot, uvC); + v.texcoord0.xy += center; + #endif + //-------------------- + + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + #if OUTTEX_ON + v.texcoord1.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + v.texcoord2.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + v.texcoord3.xy = CUSTOM_TRANSFORM_TEX(v.texcoord0.xy, _DistortTex_ScaleAndTiling); + #endif + } + + void Ext_SurfaceFunction0 (inout Surface o, ShaderData d) + { + half randomSeed = _RandomSeed; + + float2 uvRect = d.texcoord0; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((d.texcoord0.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord0.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + //CLIPPING_ON + #if CLIPPING_ON + half2 tiledUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + //---------------------------------- + + //RADIALCLIPPING_ON + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + //----------------------------- + + //TEXTURESCROLL_ON && ATLAS_ON + #if TEXTURESCROLL_ON && ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + //---------------------------- + + //OFFSETUV_ON + #if OFFSETUV_ON + #if ATLAS_ON + d.texcoord0.xy = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + d.texcoord0.xy += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + //---------------------- + + //POLARUV_ON + #if POLARUV_ON + d.texcoord0.xy = half2(atan2(d.texcoord0.y, d.texcoord0.x) / (2.0f * 3.141592653589f), length(d.texcoord0.xy)); + d.texcoord0.xy *= _MainTex_ScaleAndTiling.xy; + #endif + + //-------------------------------------- + + //TWISTUV_ON + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = d.texcoord0.xy - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + d.texcoord0.xy = tempUv; + #endif + + //-------------------------------------------- + + //FISHEYE_ON + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = d.texcoord0.xy - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + d.texcoord0.xy = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + //--------------------------------------------- + + //PINCH_ON + #if PINCH_ON + half2 dP = d.texcoord0.xy - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + d.texcoord0.xy = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + //--------------------------------------------- + + //ZOOMUV_ON + #if ZOOMUV_ON + d.texcoord0.xy -= centerTiled; + d.texcoord0.xy = d.texcoord0.xy * _ZoomUvAmount; + d.texcoord0.xy += centerTiled; + #endif + + //----------------------------------------------- + + //DOODLE_ON + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + d.texcoord0.xy = lerp(d.texcoord0.xy, d.texcoord0.xy + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + //-------------------------- + + //SHAKEUV_ON + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + d.texcoord0.xy += half2(xShake * 0.012, yShake * 0.01); + #endif + + //------------------------------------------- + + //RECTSIZE_ON + #if RECTSIZE_ON + d.texcoord0.xy = d.texcoord0.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + //------------------------------------------- + + //DISTORT_ON + #if DISTORT_ON + #if ATLAS_ON + d.texcoord3.x = d.texcoord3.x * (1 / (_MaxXUV - _MinXUV)); + d.texcoord3.y = d.texcoord3.y * (1 / (_MaxYUV - _MinYUV)); + #endif + + d.texcoord3.x += ((_Time.x + _RandomSeed) * _DistortTexXSpeed) % 1; + d.texcoord3.y += ((_Time.x + _RandomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, d.texcoord3.xy).r - 0.5) * 0.2 * _DistortAmount; + d.texcoord0.x += distortAmnt; + d.texcoord0.y += distortAmnt; + #endif + //------------------------------------------------------- + + //WARP_ON + #if WARP_ON + half2 warpUv = half2(d.texcoord0.x / _MainTex_ScaleAndTiling.x, d.texcoord0.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + d.texcoord0.xy += warp; + #endif + + //------------------------------------------------------- + + //WAVEUV_ON + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - d.texcoord0.xy; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + d.texcoord0.xy = d.texcoord0.xy + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + //---------------------------------------------------- + + //ROUNDWAVEUV_ON + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + d.texcoord0.xy += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; + #endif + //---------------------------------------------------- + + + //WIND_ON + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + d.texcoord0.x = fmod(abs(lerp(d.texcoord0.x, d.texcoord0.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = d.texcoord0.xy - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + d.texcoord0.xy = d.texcoord0.xy + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + //-------------------------------------------------------- + + //TEXTURESCROLL_ON && !ATLAS_ON + #if TEXTURESCROLL_ON && !ATLAS_ON + d.texcoord0.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + d.texcoord0.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + //------------------------------ + + //PIXELATE_ON + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + d.texcoord0.xy = floor(d.texcoord0.xy * pixelSize) / pixelSize; + #endif + //-------------- + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy); + half originalAlpha = col.a; + col *= d.vertexColor; + + //NORMAL MAP + #if NORMALMAP_ON + half4 normalSample = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, d.texcoord0.xy); + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + o.Normal = normalTS; + #endif + + + float3 lightDir; + float3 lightColor; + GetSun(lightDir, lightColor); + + + float flipNormalFactor = 1.0; + if(!d.isFrontFace){ + flipNormalFactor *= -1.0; + } + + flipNormalFactor *= _SpriteFlip.z; + o.Normal *= flipNormalFactor; + + //GLITCH_ON + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * d.vertexColor; + #endif + //-------------------------------------- + + //CHROMABERR_ON + #if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ChromAberrAmount/10, 0)) * d.vertexColor; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-_ChromAberrAmount/10, 0)) * d.vertexColor; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + //-------------------------------- + + //BLUR_ON + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * d.vertexColor; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * d.vertexColor; + #else + col = Blur(d.texcoord0.xy, _MainTex, sampler_MainTex, _BlurIntensity) * d.vertexColor; + #endif + #endif + #endif + + //-------------------- + + //MOTIONBLUR_ON + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + //------------------------------------ + + //NEGATIVE_ON + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + //-------------- + half luminance = 0; + + //GREYSCALE_ON && !GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + //------------------------------------ + + //GHOST_ON + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + //------------------------------------ + + //INNEROUTLINE_ON + #if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, d.texcoord0.xy, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, d.texcoord0.xy, _MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + //------------------------------------------------------- + + //HITEFFECT_ON + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + //-------------------- + + //GRADIENT_ON + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + //-------------------------------------------------------------------- + + //CONTRAST_ON + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + //------------------------------------------------------------------- + + //COLORSWAP_ON + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, d.texcoord0.xy); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + //-------------------------------------------------------------------- + + //COLORRAMP_ON && !COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //-------------------------------------------------------------------- + + //CHANGECOLOR_ON + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + //------------------------------------------------------- + + //POSTERIZE_ON && !POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + //------------------------------------ + + //HSV_ON + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + //------------------------------------------------------- + + //OVERLAY_ON + #if OVERLAY_ON + half2 overlayUvs = d.texcoord0.xy; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //--------------------------------- + + //OUTBASE_ON + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + d.texcoord2.x += ((_Time.x + _RandomSeed) * _OutlineDistortTexXSpeed) % 1; + d.texcoord2.y += ((_Time.x + _RandomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord2 = half2((d.texcoord2.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, d.texcoord2).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + d.texcoord1.x += ((_Time.x + _RandomSeed) * _OutlineTexXSpeed) % 1; + d.texcoord1.y += ((_Time.x + _RandomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + d.texcoord1 = half2((d.texcoord1.x - _MinXUV) / (_MaxXUV - _MinXUV), (d.texcoord1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, d.texcoord1); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * d.vertexColor.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //------------------------------------------------------- + + //FADE_ON + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(d.texcoord0, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + //------------------------------------------------------- + + //SHADOW_ON + #if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.xy + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * d.vertexColor.a, col.a); + #endif + + //------------------------------------------------------- + + //GLOW_ON + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, d.texcoord0); + #else + emission = col; + #endif + + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + //------------------------------------------------------- + + //COLORRAMP_ON && COLORRAMPOUTLINE_ON + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + //--------------- + + //GREYSCALE_ON && GREYSCALEOUTLINE_ON + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + //----------------------------------- + + //POSTERIZE_ON && POSTERIZEOUTLINE_ON + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + //----------------------------------- + + //SHINE_ON + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, d.texcoord0.xy).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + //----------------------------------- + + //HOLOGRAM_ON + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + //----------------------------------- + + //FLICKER_ON + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + //----------------------------------- + + //ALPHACUTOFF_ON + + //ALPHAROUND_ON + + //ALPHAOUTLINE_ON + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + //------------------------------------------------------- + + //FOG_ON + + //------------------ + + col *= _Color; + + col.a *= _Alpha; + o.Albedo = col; + + clip(col.a - _AlphaCutoffValue - 0.01); + o.Alpha = col.a; + } + + + + + + void ChainSurfaceFunction(inout Surface l, inout ShaderData d) + { + Ext_SurfaceFunction0(l, d); + // Ext_SurfaceFunction1(l, d); + // Ext_SurfaceFunction2(l, d); + // Ext_SurfaceFunction3(l, d); + // Ext_SurfaceFunction4(l, d); + // Ext_SurfaceFunction5(l, d); + // Ext_SurfaceFunction6(l, d); + // Ext_SurfaceFunction7(l, d); + // Ext_SurfaceFunction8(l, d); + // Ext_SurfaceFunction9(l, d); + // Ext_SurfaceFunction10(l, d); + // Ext_SurfaceFunction11(l, d); + // Ext_SurfaceFunction12(l, d); + // Ext_SurfaceFunction13(l, d); + // Ext_SurfaceFunction14(l, d); + // Ext_SurfaceFunction15(l, d); + // Ext_SurfaceFunction16(l, d); + // Ext_SurfaceFunction17(l, d); + // Ext_SurfaceFunction18(l, d); + // Ext_SurfaceFunction19(l, d); + // Ext_SurfaceFunction20(l, d); + // Ext_SurfaceFunction21(l, d); + // Ext_SurfaceFunction22(l, d); + // Ext_SurfaceFunction23(l, d); + // Ext_SurfaceFunction24(l, d); + // Ext_SurfaceFunction25(l, d); + // Ext_SurfaceFunction26(l, d); + // Ext_SurfaceFunction27(l, d); + // Ext_SurfaceFunction28(l, d); + // Ext_SurfaceFunction29(l, d); + } + +#if !_DECALSHADER + + void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time) + { + ExtraV2F d; + + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + // due to motion vectors in HDRP, we need to use the last + // time in certain spots. So if you are going to use _Time to adjust vertices, + // you need to use this time or motion vectors will break. + d.time = time; + + Ext_ModifyVertex0(v, d); + // Ext_ModifyVertex1(v, d); + // Ext_ModifyVertex2(v, d); + // Ext_ModifyVertex3(v, d); + // Ext_ModifyVertex4(v, d); + // Ext_ModifyVertex5(v, d); + // Ext_ModifyVertex6(v, d); + // Ext_ModifyVertex7(v, d); + // Ext_ModifyVertex8(v, d); + // Ext_ModifyVertex9(v, d); + // Ext_ModifyVertex10(v, d); + // Ext_ModifyVertex11(v, d); + // Ext_ModifyVertex12(v, d); + // Ext_ModifyVertex13(v, d); + // Ext_ModifyVertex14(v, d); + // Ext_ModifyVertex15(v, d); + // Ext_ModifyVertex16(v, d); + // Ext_ModifyVertex17(v, d); + // Ext_ModifyVertex18(v, d); + // Ext_ModifyVertex19(v, d); + // Ext_ModifyVertex20(v, d); + // Ext_ModifyVertex21(v, d); + // Ext_ModifyVertex22(v, d); + // Ext_ModifyVertex23(v, d); + // Ext_ModifyVertex24(v, d); + // Ext_ModifyVertex25(v, d); + // Ext_ModifyVertex26(v, d); + // Ext_ModifyVertex27(v, d); + // Ext_ModifyVertex28(v, d); + // Ext_ModifyVertex29(v, d); + + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p) + { + ExtraV2F d; + ZERO_INITIALIZE(ExtraV2F, d); + ZERO_INITIALIZE(Blackboard, d.blackboard); + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = v2p.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = v2p.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = v2p.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = v2p.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = v2p.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = v2p.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = v2p.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = v2p.extraV2F7; + // #endif + + + // Ext_ModifyTessellatedVertex0(v, d); + // Ext_ModifyTessellatedVertex1(v, d); + // Ext_ModifyTessellatedVertex2(v, d); + // Ext_ModifyTessellatedVertex3(v, d); + // Ext_ModifyTessellatedVertex4(v, d); + // Ext_ModifyTessellatedVertex5(v, d); + // Ext_ModifyTessellatedVertex6(v, d); + // Ext_ModifyTessellatedVertex7(v, d); + // Ext_ModifyTessellatedVertex8(v, d); + // Ext_ModifyTessellatedVertex9(v, d); + // Ext_ModifyTessellatedVertex10(v, d); + // Ext_ModifyTessellatedVertex11(v, d); + // Ext_ModifyTessellatedVertex12(v, d); + // Ext_ModifyTessellatedVertex13(v, d); + // Ext_ModifyTessellatedVertex14(v, d); + // Ext_ModifyTessellatedVertex15(v, d); + // Ext_ModifyTessellatedVertex16(v, d); + // Ext_ModifyTessellatedVertex17(v, d); + // Ext_ModifyTessellatedVertex18(v, d); + // Ext_ModifyTessellatedVertex19(v, d); + // Ext_ModifyTessellatedVertex20(v, d); + // Ext_ModifyTessellatedVertex21(v, d); + // Ext_ModifyTessellatedVertex22(v, d); + // Ext_ModifyTessellatedVertex23(v, d); + // Ext_ModifyTessellatedVertex24(v, d); + // Ext_ModifyTessellatedVertex25(v, d); + // Ext_ModifyTessellatedVertex26(v, d); + // Ext_ModifyTessellatedVertex27(v, d); + // Ext_ModifyTessellatedVertex28(v, d); + // Ext_ModifyTessellatedVertex29(v, d); + + // #if %EXTRAV2F0REQUIREKEY% + // v2p.extraV2F0 = d.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // v2p.extraV2F1 = d.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // v2p.extraV2F2 = d.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // v2p.extraV2F3 = d.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // v2p.extraV2F4 = d.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // v2p.extraV2F5 = d.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // v2p.extraV2F6 = d.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // v2p.extraV2F7 = d.extraV2F7; + // #endif + } + + void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color) + { + // Ext_FinalColorForward0(l, d, color); + // Ext_FinalColorForward1(l, d, color); + // Ext_FinalColorForward2(l, d, color); + // Ext_FinalColorForward3(l, d, color); + // Ext_FinalColorForward4(l, d, color); + // Ext_FinalColorForward5(l, d, color); + // Ext_FinalColorForward6(l, d, color); + // Ext_FinalColorForward7(l, d, color); + // Ext_FinalColorForward8(l, d, color); + // Ext_FinalColorForward9(l, d, color); + // Ext_FinalColorForward10(l, d, color); + // Ext_FinalColorForward11(l, d, color); + // Ext_FinalColorForward12(l, d, color); + // Ext_FinalColorForward13(l, d, color); + // Ext_FinalColorForward14(l, d, color); + // Ext_FinalColorForward15(l, d, color); + // Ext_FinalColorForward16(l, d, color); + // Ext_FinalColorForward17(l, d, color); + // Ext_FinalColorForward18(l, d, color); + // Ext_FinalColorForward19(l, d, color); + // Ext_FinalColorForward20(l, d, color); + // Ext_FinalColorForward21(l, d, color); + // Ext_FinalColorForward22(l, d, color); + // Ext_FinalColorForward23(l, d, color); + // Ext_FinalColorForward24(l, d, color); + // Ext_FinalColorForward25(l, d, color); + // Ext_FinalColorForward26(l, d, color); + // Ext_FinalColorForward27(l, d, color); + // Ext_FinalColorForward28(l, d, color); + // Ext_FinalColorForward29(l, d, color); + } + + void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask) + { + // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask); + } +#endif + + + + + +#if _DECALSHADER + + ShaderData CreateShaderData(SurfaceDescriptionInputs IN) + { + ShaderData d = (ShaderData)0; + d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal); + d.worldSpaceNormal = IN.WorldSpaceNormal; + d.worldSpaceTangent = IN.WorldSpaceTangent; + + d.worldSpacePosition = IN.WorldSpacePosition; + d.texcoord0 = IN.uv0.xyxy; + d.screenPos = IN.ScreenPosition; + + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(d.worldSpacePosition); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(d.worldSpacePosition, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), d.worldSpaceTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w)); + // #endif + + return d; + } +#else + + ShaderData CreateShaderData(VertexToPixel i + #if NEED_FACING + , bool facing + #endif + ) + { + ShaderData d = (ShaderData)0; + d.clipPos = i.pos; + d.worldSpacePosition = i.worldPos; + + d.worldSpaceNormal = normalize(i.worldNormal); + d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz); + + d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign; + + d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal); + #if _HDRP || _URP + d.worldSpaceViewDir = GetWorldSpaceNormalizeViewDir(i.worldPos); + #else + d.worldSpaceViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos)); + #endif + + d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir); + d.texcoord0 = i.texcoord0; + d.texcoord1 = i.texcoord1; + d.texcoord2 = i.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + d.texcoord3 = i.texcoord3; + // #endif + + d.isFrontFace = facing; + // #if %VERTEXCOLORREQUIREKEY% + d.vertexColor = i.vertexColor; + // #endif + + // these rarely get used, so we back transform them. Usually will be stripped. + #if _HDRP + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz; + #else + // d.localSpacePosition = mul(GetWorldToObjectMatrix(), float4(i.worldPos, 1)).xyz; + #endif + // d.localSpaceNormal = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldNormal)); + // d.localSpaceTangent = normalize(mul((float3x3)GetWorldToObjectMatrix(), i.worldTangent.xyz)); + + // #if %SCREENPOSREQUIREKEY% + // d.screenPos = i.screenPos; + // d.screenUV = (i.screenPos.xy / i.screenPos.w); + // #endif + + + // #if %EXTRAV2F0REQUIREKEY% + // d.extraV2F0 = i.extraV2F0; + // #endif + + // #if %EXTRAV2F1REQUIREKEY% + // d.extraV2F1 = i.extraV2F1; + // #endif + + // #if %EXTRAV2F2REQUIREKEY% + // d.extraV2F2 = i.extraV2F2; + // #endif + + // #if %EXTRAV2F3REQUIREKEY% + // d.extraV2F3 = i.extraV2F3; + // #endif + + // #if %EXTRAV2F4REQUIREKEY% + // d.extraV2F4 = i.extraV2F4; + // #endif + + // #if %EXTRAV2F5REQUIREKEY% + // d.extraV2F5 = i.extraV2F5; + // #endif + + // #if %EXTRAV2F6REQUIREKEY% + // d.extraV2F6 = i.extraV2F6; + // #endif + + // #if %EXTRAV2F7REQUIREKEY% + // d.extraV2F7 = i.extraV2F7; + // #endif + + return d; + } + +#endif + + + #if defined(_PASSSHADOW) + float3 _LightDirection; + float3 _LightPosition; + #endif + + #if (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + + #define GetWorldToViewMatrix() _ViewMatrix + #define UNITY_MATRIX_I_V _InvViewMatrix + #define GetViewToHClipMatrix() OptimizeProjectionMatrix(_ProjMatrix) + #define UNITY_MATRIX_I_P _InvProjMatrix + #define GetWorldToHClipMatrix() _ViewProjMatrix + #define UNITY_MATRIX_I_VP _InvViewProjMatrix + #define UNITY_MATRIX_UNJITTERED_VP _NonJitteredViewProjMatrix + #define UNITY_MATRIX_PREV_VP _PrevViewProjMatrix + #define UNITY_MATRIX_PREV_I_VP _PrevInvViewProjMatrix + + void MotionVectorPositionZBias(VertexToPixel input) + { + #if UNITY_REVERSED_Z + input.pos.z -= unity_MotionVectorsParams.z * input.pos.w; + #else + input.pos.z += unity_MotionVectorsParams.z * input.pos.w; + #endif + } + + #endif + + // vertex shader + VertexToPixel Vert (VertexData v) + { + VertexToPixel o = (VertexToPixel)0; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + VertexData previousMesh = v; + #endif + #if !_TESSELLATION_ON + ChainModifyVertex(v, o, _Time); + #endif + + o.texcoord0 = v.texcoord0; + o.texcoord1 = v.texcoord1; + o.texcoord2 = v.texcoord2; + + // #if %TEXCOORD3REQUIREKEY% + o.texcoord3 = v.texcoord3; + // #endif + + // #if %VERTEXCOLORREQUIREKEY% + o.vertexColor = v.vertexColor; + // #endif + + // This return the camera relative position (if enable) + float3 positionWS = TransformObjectToWorld(v.vertex.xyz); + float3 normalWS = TransformObjectToWorldNormal(v.normal); + float4 tangentWS = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w); + + VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); + o.worldPos = positionWS; + o.worldNormal = normalWS; + o.worldTangent = tangentWS; + + + // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own.. + #if _PASSSHADOW + #if _CASTING_PUNCTUAL_LIGHT_SHADOW + float3 lightDirectionWS = normalize(_LightPosition - o.worldPos); + #else + float3 lightDirectionWS = _LightDirection; + #endif + // Define shadow pass specific clip position for Universal + o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS)); + #if UNITY_REVERSED_Z + o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #else + o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE); + #endif + #elif _PASSMETA + o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST); + #else + o.pos = TransformWorldToHClip(o.worldPos); + #endif + + // #if %SCREENPOSREQUIREKEY% + // o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x); + // #endif + + + #if _PASSFORWARD || _PASSGBUFFER + float2 uv1 = v.texcoord1.xy; + OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV); + o.texcoord1.xy = uv1; + #if UNITY_VERSION < 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + + #if defined(DYNAMICLIGHTMAP_ON) + o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; + #if UNITY_VERSION >= 60000009 + OUTPUT_SH(o.worldNormal, o.sh); + #endif + #elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && UNITY_VERSION >= 60000009 + OUTPUT_SH4(vertexInput.positionWS, o.worldNormal.xyz, GetWorldSpaceNormalizeViewDir(vertexInput.positionWS), o.sh, o.probeOcclusion); + #endif + #endif + + #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT + half fogFactor = 0; + #if defined(_FOG_FRAGMENT) + fogFactor = ComputeFogFactor(o.pos.z); + #endif + #if _BAKEDLIT + o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0); + #else + half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal); + o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + #endif + #endif + + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + o.shadowCoord = GetShadowCoord(vertexInput); + #endif + + #if _URP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR))) + #if !defined(TESSELLATION_ON) + MotionVectorPositionZBias(o); + #endif + + o.previousPositionCS = float4(0.0, 0.0, 0.0, 1.0); + // Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled + bool forceNoMotion = unity_MotionVectorsParams.y == 0.0; + + if (!forceNoMotion) + { + #if defined(HAVE_VFX_MODIFICATION) + float3 previousPositionOS = currentFrameMvData.vfxParticlePositionOS; + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + const bool applyDeformation = false; + #else + const bool applyDeformation = true; + #endif + #else + const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation + float3 previousPositionOS = hasDeformation ? previousMesh.previousPositionOS : previousMesh.vertex.xyz; + + #if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT) + const bool applyDeformation = true; + #else + const bool applyDeformation = hasDeformation; + #endif + #endif + // TODO + #if defined(FEATURES_GRAPH_VERTEX) + if (applyDeformation) + previousPositionOS = GetLastFrameDeformedPosition(previousMesh, currentFrameMvData, previousPositionOS); + else + previousPositionOS = previousMesh.positionOS; + + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + #endif + + #if defined(UNITY_DOTS_INSTANCING_ENABLED) && defined(DOTS_DEFORMED) + // Deformed vertices in DOTS are not cumulative with built-in Unity skinning/blend shapes + // Needs to be called after vertex modification has been applied otherwise it will be + // overwritten by Compute Deform node + ApplyPreviousFrameDeformedVertexPosition(previousMesh.vertexID, previousPositionOS); + #endif + #if defined (_ADD_PRECOMPUTED_VELOCITY) + previousPositionOS -= previousMesh.precomputedVelocity; + #endif + o.positionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionWS, 1.0f)); + + #if defined(HAVE_VFX_MODIFICATION) + #if defined(VFX_FEATURE_MOTION_VECTORS_VERTS) + #if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT) || defined(_ADD_PRECOMPUTED_VELOCITY) + #error Unexpected fast path rendering VFX motion vector while there are vertex modification afterwards. + #endif + o.previousPositionCS = VFXGetPreviousClipPosition(previousMesh, currentFrameMvData.vfxElementAttributes, o.positionCS); + #else + #if VFX_WORLD_SPACE + //previousPositionOS is already in world space + const float3 previousPositionWS = previousPositionOS; + #else + const float3 previousPositionWS = mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f)).xyz; + #endif + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionWS, 1.0f)); + #endif + #else + o.previousPositionCS = mul(UNITY_MATRIX_PREV_VP, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1))); + #endif + } + #endif + + return o; + } + + + + + // fragment shader + half4 Frag (VertexToPixel IN + #ifdef _DEPTHOFFSET_ON + , out float outputDepth : SV_Depth + #endif + #if NEED_FACING + , bool facing : SV_IsFrontFace + #endif + ) : SV_Target + { + UNITY_SETUP_INSTANCE_ID(IN); + + #if defined(LOD_FADE_CROSSFADE) + LODFadeCrossFade(IN.pos); + #endif + + ShaderData d = CreateShaderData(IN + #if NEED_FACING + , facing + #endif + ); + Surface l = (Surface)0; + + #ifdef _DEPTHOFFSET_ON + l.outputDepth = outputDepth; + #endif + + l.Albedo = half3(0.5, 0.5, 0.5); + l.Normal = float3(0,0,1); + l.Occlusion = 1; + l.Alpha = 1; + + ChainSurfaceFunction(l, d); + + #ifdef _DEPTHOFFSET_ON + outputDepth = l.outputDepth; + #endif + + return 0; + + } + + ENDHLSL + + } + + + + + } + + + CustomEditor "AllIn1SpriteShader.AllIn1SpriteShaderLitMaterialInspector" +} diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2023.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2023.txt.meta new file mode 100644 index 0000000..7ca1f72 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2023.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: a84fbc897c8eaaf40b7075fd17cdbb7f +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/AllIn1SpriteShaderLit_BetterShader_URP2023.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/README.txt b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/README.txt new file mode 100644 index 0000000..612a832 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/README.txt @@ -0,0 +1,31 @@ +# BetterShaders_AllIn1Sprite Shader + +This shader was created using Better Shaders, a Unity asset by Jason Booth that simplifies cross-pipeline shader development. + +## Usage +- If you own Better Shaders: You can modify the shader's source code: AllIn1SpriteShaderLit_BetterShader.surfshader +- If you don't own Better Shaders: A pre-compiled version matching your current Render Pipeline and Unity version will be automatically set up. + +## Why Better Shaders? +Better Shaders was used because Unity doesn't have an easy way to create hand written lit shaders compatible across all render pipelines. + +## About Better Shaders +Better Shaders streamlines shader creation by: +- Enabling Unity-like shader writing +- Auto-compiling for various pipelines +- Allowing shader stacking +- Functioning like native Unity shaders + +For more information or to purchase Better Shaders, visit: +[Better Shaders on Unity Asset Store](https://assetstore.unity.com/packages/tools/visual-scripting/better-shaders-2022-standard-urp-hdrp-244057) + +## What are all the .txt shaders and how to export them? +The .txt shaders are the pipeline-specific source code for the shader. You can export them by: +1. Selecting AllIn1SpriteShaderLit_BetterShader.surfshader +2. Export all shaders as text assets + +Doing this will cause some URP and HDRP shaders material inspectors properties to be in the incorrect order. To fix this, you can: +1. Localize the Better Shaders2022 folder +2. Inside you'll see the PipelineTemplates folder +3. There, find your pipeline's template +4. Make sure that "%PROPERTIES%" is right under "Properties{" diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/README.txt.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/README.txt.meta new file mode 100644 index 0000000..45ee2b8 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/README.txt.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 4026e642526007b45b74a1f1064e6ba2 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/LitShaders/README.txt + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary.meta new file mode 100644 index 0000000..c7ac1dc --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a8c7136836fcfb3448e5f1822a7192d9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer.meta new file mode 100644 index 0000000..4733f79 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 786a2bacb5f53844392f7846e0ff411c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl new file mode 100644 index 0000000..c7c16d9 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl @@ -0,0 +1,87 @@ +#ifndef ALLIN1SPRITESHADER_2DRENDERER_COMMONFUNCTIONS +#define ALLIN1SPRITESHADER_2DRENDERER_COMMONFUNCTIONS + +//Prevent Unity warnings that are not relevant for this shader------------------- +#pragma warning (disable : 3571) // pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them +#pragma warning (disable : 4008) // floating point division by zero +#pragma warning (disable : 3206) // implicit truncation of vector type +//BLURS------------------------------------------------------------------------- + + +#define ALLIN1_SAMPLE_TEXTURE_2D(texName, uv) SAMPLE_TEXTURE2D(texName, sampler##texName, uv) + +half4 Blur(half2 uv, Texture2D source, SamplerState texSampler, half Intensity) +{ + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, texSampler, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, texSampler, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; +} + +half BlurHD_G(half bhqp, half x) +{ + return exp(-(x * x) / (2.0 * bhqp * bhqp)); +} +half4 BlurHD(half2 uv, Texture2D source, SamplerState texSampler, half BlurAmount, half xScale, half yScale) +{ + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, texSampler, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; +} +//----------------------------------------------------------------------- +half rand(half offset, half2 seed) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; +} + +half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; +} + +half rand2CustomTime(half offset, half2 seed, half customTime, half speed) { + return (frac(sin(dot(seed * floor(50 + (customTime % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; +} +//----------------------------------------------------------------------- +half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); +} + +half3 GetPixel(in int offsetX, in int offsetY, half2 uv, Texture2D tex, SamplerState texSampler, float4 texelSize) +{ + half2 correctedUV = (uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)); + half3 res = SAMPLE_TEXTURE2D(tex, texSampler, correctedUV).rgb; + return res; +} + +#endif //ALLIN1SPRITESHADER_2DRENDERER_COMMONFUNCTIONS \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl.meta new file mode 100644 index 0000000..cb386f9 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: b271c3be2c8bda1448755707cbb814cd +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_CommonFunctions.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_FragmentPass.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_FragmentPass.hlsl new file mode 100644 index 0000000..7c92bd5 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_FragmentPass.hlsl @@ -0,0 +1,588 @@ +#ifndef ALLIN1SPRITESHADER_2DRENDERER_FRAGMENTPASS +#define ALLIN1SPRITESHADER_2DRENDERER_FRAGMENTPASS + +half4 CombinedShapeLightFragment(v2f i) : SV_Target +{ + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + half randomSeed = _RandomSeed; + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + float2 uvRect = i.uv; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((i.uv.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + #if CLIPPING_ON + half2 tiledUv = half2(i.uv.x / _MainTex_ScaleAndTiling.x, i.uv.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(i.uv.x / _MainTex_ScaleAndTiling.x, i.uv.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + #if TEXTURESCROLL_ON && ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + + #if OFFSETUV_ON + #if ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + i.uv += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + #if POLARUV_ON + i.uv = half2(atan2(i.uv.y, i.uv.x) / (2.0f * 3.141592653589f), length(i.uv)); + i.uv *= _MainTex_ScaleAndTiling.xy; + #endif + + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = i.uv - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + i.uv = tempUv; + #endif + + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = i.uv - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + i.uv = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + + #if PINCH_ON + half2 dP = i.uv - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + i.uv = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + #if ZOOMUV_ON + i.uv -= centerTiled; + i.uv = i.uv * _ZoomUvAmount; + i.uv += centerTiled; + #endif + + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + i.uv = lerp(i.uv, i.uv + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + i.uv += half2(xShake * 0.012, yShake * 0.01); + #endif + + #if RECTSIZE_ON + i.uv = i.uv.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + #if DISTORT_ON + #if ATLAS_ON + i.uvDistTex.x = i.uvDistTex.x * (1 / (_MaxXUV - _MinXUV)); + i.uvDistTex.y = i.uvDistTex.y * (1 / (_MaxYUV - _MinYUV)); + #endif + i.uvDistTex.x += ((_Time.x + randomSeed) * _DistortTexXSpeed) % 1; + i.uvDistTex.y += ((_Time.x + randomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (ALLIN1_SAMPLE_TEXTURE_2D(_DistortTex, i.uvDistTex).r - 0.5) * 0.2 * _DistortAmount; + i.uv.x += distortAmnt; + i.uv.y += distortAmnt; + #endif + + #if WARP_ON + half2 warpUv = half2(i.uv.x / _MainTex_ScaleAndTiling.x, i.uv.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + i.uv += warp; + #endif + + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - i.uv; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + i.uv = i.uv + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + i.uv += sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0); + #endif + + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = i.uv - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + i.uv = i.uv + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + #if TEXTURESCROLL_ON && !ATLAS_ON + i.uv.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + i.uv.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + i.uv = floor(i.uv * pixelSize) / pixelSize; + #endif + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); + half originalAlpha = col.a; + col *= i.color; + #if PREMULTIPLYALPHA_ON + col.rgb *= col.a; + #endif + + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * i.color; + #endif + + #if CHROMABERR_ON + half4 r = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(_ChromAberrAmount/10, 0)) * i.color; + half4 b = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(-_ChromAberrAmount/10, 0)) * i.color; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * i.color; + #else + col = Blur(i.uv, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * i.color; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * i.color; + #else + col = Blur(i.uv, _MainTex, sampler_MainTex, _BlurIntensity) * i.color; + #endif + #endif + #endif + + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + #if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); + #endif + col.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; + #endif + + #if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); + #endif + + half luminance = 0; + #if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + + #if INNEROUTLINE_ON + half3 innerT = abs(GetPixel(0, _InnerOutlineThickness, i.uv, _MainTex, sampler_MainTex, texelSize) - GetPixel(0, -_InnerOutlineThickness, i.uv, _MainTex, sampler_MainTex, texelSize)); + innerT += abs(GetPixel(_InnerOutlineThickness, 0, i.uv, _MainTex, sampler_MainTex, texelSize) - GetPixel(-_InnerOutlineThickness, 0, i.uv, _MainTex, sampler_MainTex, texelSize)); + #if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + #else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); + #endif + #endif + + #if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); + #endif + + #if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); + #if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; + #endif + #if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); + #else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); + #endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; + #endif + + #if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; + #endif + + #if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = ALLIN1_SAMPLE_TEXTURE_2D(_ColorSwapTex, i.uv); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * col.a * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * col.a * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * col.a * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); + #endif + + #if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, ALLIN1_SAMPLE_TEXTURE_2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, ALLIN1_SAMPLE_TEXTURE_2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + + #if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); + #if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); + #endif + #if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); + #endif + #endif + + #if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + #if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; + #endif + + #if OVERLAY_ON + half2 overlayUvs = i.uv; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = ALLIN1_SAMPLE_TEXTURE_2D(_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //OUTLINE------------------------------------------------------------- + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + i.uvOutDistTex.x += ((_Time.x + randomSeed) * _OutlineDistortTexXSpeed) % 1; + i.uvOutDistTex.y += ((_Time.x + randomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + i.uvOutDistTex = half2((i.uvOutDistTex.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uvOutDistTex.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (ALLIN1_SAMPLE_TEXTURE_2D(_OutlineDistortTex, i.uvOutDistTex).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(destUv.x, 0)).a; + half spriteRight = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv - half2(destUv.x, 0)).a; + half spriteBottom = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(0, destUv.y)).a; + half spriteTop = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(destUv.x, destUv.y)).a; + half spriteTopRight = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + i.uvOutTex.x += ((_Time.x + randomSeed) * _OutlineTexXSpeed) % 1; + i.uvOutTex.y += ((_Time.x + randomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + i.uvOutTex = half2((i.uvOutTex.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uvOutTex.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = ALLIN1_SAMPLE_TEXTURE_2D(_OutlineTex, i.uvOutTex); + #if OUTGREYTEXTURE_ON + luminance = 0.3 * tempOutColor.r + 0.59 * tempOutColor.g + 0.11 * tempOutColor.b; + tempOutColor = half4(luminance, luminance, luminance, 1); + #endif + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * i.color.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //----------------------------------------------------------------------------- + + #if FADE_ON + half2 tiledUvFade1= CUSTOM_TRANSFORM_TEX(i.uv, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(i.uv, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = ALLIN1_SAMPLE_TEXTURE_2D(_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * ALLIN1_SAMPLE_TEXTURE_2D(_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + + #if SHADOW_ON + half shadowA = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * i.color.a, col.a); + #endif + + #if GLOW_ON + half4 emission; + #if GLOWTEX_ON + emission = ALLIN1_SAMPLE_TEXTURE_2D(_GlowTex, i.uv); + #else + emission = col; + #endif + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; + #endif + + #if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); + #if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, ALLIN1_SAMPLE_TEXTURE_2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); + #else + col.rgb = lerp(col.rgb, ALLIN1_SAMPLE_TEXTURE_2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); + #endif + #endif + + #if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); + #endif + + #if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); + #endif + + #if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = ALLIN1_SAMPLE_TEXTURE_2D(_ShineMask, i.uv).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; + #endif + + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + + col.a *= _Alpha; + + #if ALPHACUTOFF_ON + clip((1 - _AlphaCutoffValue) - (1 - col.a) - 0.01); + #endif + + #if ALPHAROUND_ON + col.a = step(_AlphaRoundThreshold, col.a); + #endif + + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + + col *= _Color; + originalAlpha = col.a; + + half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv); + mask.rgb *= _LitAmount; + mask = saturate(mask); + SurfaceData2D surfaceData; + InputData2D inputData; + surfaceData.albedo = col.rgb; + surfaceData.alpha = col.a; + surfaceData.mask = mask; + inputData.uv = i.uv; + inputData.lightingUV = i.lightingUV; + half3 lightResult = CombinedShapeLightShared(surfaceData, inputData).rgb; + + #if GLOWLIGHT_ON + mask.rgb += mask.rgb; + mask.rgb -= col.rgb; + mask.rgb = saturate(mask.rgb); + col.rgb = lerp(col.rgb, lightResult, mask.rgb); + #else + col.rgb = lightResult; + #endif + + return col; +} + +#endif //ALLIN1SPRITESHADER_2DRENDERER_FRAGMENTPASS \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_FragmentPass.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_FragmentPass.hlsl.meta new file mode 100644 index 0000000..d33ca7a --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_FragmentPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 20a889619f1033c4497fa398bd65d8a4 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_FragmentPass.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingFragmentPass.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingFragmentPass.hlsl new file mode 100644 index 0000000..f73e156 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingFragmentPass.hlsl @@ -0,0 +1,405 @@ +#ifndef ALLIN1SPRITESHADER_2DRENDERER_NORMALSRENDERINGFRAGMENTPASS +#define ALLIN1SPRITESHADER_2DRENDERER_NORMALSRENDERINGFRAGMENTPASS + +float4 NormalsRenderingFragment(FragmentDataNormalsPass i) : SV_Target +{ + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + half randomSeed = UNITY_ACCESS_INSTANCED_PROP(Props, _RandomSeed); + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + float2 uvRect = i.uv; + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((i.uv.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + + #if CLIPPING_ON + half2 tiledUv = half2(i.uv.x / _MainTex_ScaleAndTiling.x, i.uv.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); + #endif + + #if RADIALCLIPPING_ON + half2 tiledUv2 = half2(i.uv.x / _MainTex_ScaleAndTiling.x, i.uv.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; + #endif + + #if TEXTURESCROLL_ON && ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); + #endif + + #if OFFSETUV_ON + #if ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); + #else + i.uv += half2(_OffsetUvX, _OffsetUvY); + #endif + #endif + + #if POLARUV_ON + i.uv = half2(atan2(i.uv.y, i.uv.x) / (2.0f * 3.141592653589f), length(i.uv)); + i.uv *= _MainTex_ScaleAndTiling.xy; + #endif + + #if TWISTUV_ON + #if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; + #endif + half2 tempUv = i.uv - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + i.uv = tempUv; + #endif + + #if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = i.uv - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + i.uv = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); + #endif + + #if PINCH_ON + half2 dP = i.uv - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + i.uv = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); + #endif + + #if ZOOMUV_ON + i.uv -= centerTiled; + i.uv = i.uv * _ZoomUvAmount; + i.uv += centerTiled; + #endif + + #if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + i.uv = lerp(i.uv, i.uv + uvCopy, 0.0005 * _HandDrawnAmount); + #endif + + #if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + i.uv += half2(xShake * 0.012, yShake * 0.01); + #endif + + #if RECTSIZE_ON + i.uv = i.uv.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; + #endif + + #if DISTORT_ON + #if ATLAS_ON + i.uvDistTex.x = i.uvDistTex.x * (1 / (_MaxXUV - _MinXUV)); + i.uvDistTex.y = i.uvDistTex.y * (1 / (_MaxYUV - _MinYUV)); + #endif + i.uvDistTex.x += ((_Time.x + randomSeed) * _DistortTexXSpeed) % 1; + i.uvDistTex.y += ((_Time.x + randomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (ALLIN1_SAMPLE_TEXTURE_2D(_DistortTex, i.uvDistTex).r - 0.5) * 0.2 * _DistortAmount; + i.uv.x += distortAmnt; + i.uv.y += distortAmnt; + #endif + + #if WARP_ON + half2 warpUv = half2(i.uv.x / _MainTex_ScaleAndTiling.x, i.uv.y / _MainTex_ScaleAndTiling.y); + #if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + i.uv += warp; + #endif + + #if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - i.uv; + uvWave %= 1; + #if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; + #endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + i.uv = i.uv + uvWave * sin(angWave) * (_WaveStrength / 1000.0); + #endif + + #if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + i.uv += sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0); + #endif + + #if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); + #if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; + #endif + #if !MANUALWIND_ON + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); + #else + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; + #endif + half2 delta = i.uv - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + i.uv = i.uv + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; + #endif + + #if TEXTURESCROLL_ON && !ATLAS_ON + i.uv.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + i.uv.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; + #endif + + #if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + i.uv = floor(i.uv * pixelSize) / pixelSize; + #endif + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); + half originalAlpha = col.a; + col *= i.color; + #if PREMULTIPLYALPHA_ON + col.rgb *= col.a; + #endif + + #if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * i.color; + #endif + + #if CHROMABERR_ON + half4 r = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(_ChromAberrAmount/10, 0)) * i.color; + half4 b = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(-_ChromAberrAmount/10, 0)) * i.color; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); + #endif + + #if BLUR_ON + #if ATLAS_ON + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * i.color; + #else + col = Blur(i.uv, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * i.color; + #endif + #else + #if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * i.color; + #else + col = Blur(i.uv, _MainTex, sampler_MainTex, _BlurIntensity) * i.color; + #endif + #endif + #endif + + half luminance = 0; + #if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); + #endif + + #if OVERLAY_ON + half2 overlayUvs = i.uv; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = ALLIN1_SAMPLE_TEXTURE_2D(_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; + #if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; + #else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); + #endif + #endif + + //OUTLINE------------------------------------------------------------- + #if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + i.uvOutDistTex.x += ((_Time.x + randomSeed) * _OutlineDistortTexXSpeed) % 1; + i.uvOutDistTex.y += ((_Time.x + randomSeed) * _OutlineDistortTexYSpeed) % 1; + #if ATLAS_ON + i.uvOutDistTex = half2((i.uvOutDistTex.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uvOutDistTex.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half outDistortAmnt = (ALLIN1_SAMPLE_TEXTURE_2D(_OutlineDistortTex, i.uvOutDistTex).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(destUv.x, 0)).a; + half spriteRight = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv - half2(destUv.x, 0)).a; + half spriteBottom = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(0, destUv.y)).a; + half spriteTop = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv - half2(0, destUv.y)).a; + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(destUv.x, destUv.y)).a; + half spriteTopRight = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = ALLIN1_SAMPLE_TEXTURE_2D(_MainTex, i.uv + half2(-destUv.x, -destUv.y)).a; + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + i.uvOutTex.x += ((_Time.x + randomSeed) * _OutlineTexXSpeed) % 1; + i.uvOutTex.y += ((_Time.x + randomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + i.uvOutTex = half2((i.uvOutTex.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uvOutTex.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = ALLIN1_SAMPLE_TEXTURE_2D(_OutlineTex, i.uvOutTex); + #if OUTGREYTEXTURE_ON + luminance = 0.3 * tempOutColor.r + 0.59 * tempOutColor.g + 0.11 * tempOutColor.b; + tempOutColor = half4(luminance, luminance, luminance, 1); + #endif + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * i.color.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif + #endif + //----------------------------------------------------------------------------- + + #if FADE_ON + half2 tiledUvFade1 = CUSTOM_TRANSFORM_TEX(i.uv, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(i.uv, _FadeBurnTex_ScaleAndTiling); + #if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half fadeTemp = ALLIN1_SAMPLE_TEXTURE_2D(_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * ALLIN1_SAMPLE_TEXTURE_2D(_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); + #endif + + #if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); + #endif + + #if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); + #endif + + col.a *= _Alpha; + + #if ALPHACUTOFF_ON + clip((1 - _AlphaCutoffValue) - (1 - col.a) - 0.01); + #endif + + #if ALPHAROUND_ON + col.a = step(_AlphaRoundThreshold, col.a); + #endif + + #if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); + #endif + + col *= _Color; + originalAlpha = col.a; + + half4 normalSample = ALLIN1_SAMPLE_TEXTURE_2D(_NormalMap, i.uv); + + #if BLUR_ON + #if !BLURISHD_ON + normalSample = BlurHD(i.uv, _NormalMap, sampler_NormalMap, _BlurIntensity, 1, 1); + #else + normalSample = Blur(i.uv, _NormalMap, sampler_NormalMap, _BlurIntensity); + #endif + #endif + + #if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; + #define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; + normalSample.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_NormalMap, i.uv + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + normalSample.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_NormalMap, i.uv + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + normalSample.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_NormalMap, i.uv + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + normalSample.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_NormalMap, i.uv + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + normalSample.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_NormalMap, i.uv + rot(half2(_MotionBlurDist, _MotionBlurDist))); + normalSample.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_NormalMap, i.uv + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + normalSample.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_NormalMap, i.uv + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + normalSample.rgb += ALLIN1_SAMPLE_TEXTURE_2D(_NormalMap, i.uv + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + normalSample.rgb = normalSample.rgb / 9; + #endif + + half3 normalTS = UnpackNormal(normalSample); + normalTS.xy *= _NormalStrength; + + return NormalsRenderingShared(col, normalTS, i.tangentWS.xyz, i.bitangentWS.xyz, i.normalWS.xyz); +} + +#endif //ALLIN1SPRITESHADER_2DRENDERER_NORMALSRENDERINGFRAGMENTPASS \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingFragmentPass.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingFragmentPass.hlsl.meta new file mode 100644 index 0000000..757e0e2 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingFragmentPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: b4b37519e6c679e49b918bbb9e1ee73a +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingFragmentPass.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingVertexPass.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingVertexPass.hlsl new file mode 100644 index 0000000..e323cbe --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingVertexPass.hlsl @@ -0,0 +1,68 @@ +#ifndef ALLIN1SPRITESHADER_2DRENDERER_NORMALSRENDERINGVERTEXPASS +#define ALLIN1SPRITESHADER_2DRENDERER_NORMALSRENDERINGVERTEXPASS + +FragmentDataNormalsPass NormalsRenderingVertex(VertexDataNormalsPass v) +{ + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + FragmentDataNormalsPass o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + half3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + o.vertex = TransformObjectToHClip(localPos); + #else + o.vertex = TransformObjectToHClip(v.vertex.xyz); + #endif + o.uv = /*TRANSFORM_TEX(v.uv, _MainTex);*/v.uv * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + o.color = v.color; + + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + #if POLARUV_ON + o.uv = v.uv - center; + #endif + + #if ROTATEUV_ON + half2 uvC = v.uv; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + o.uv = mul(rot, uvC); + o.uv += center; + #endif + + #if OUTTEX_ON + o.uvOutTex = CUSTOM_TRANSFORM_TEX(v.uv, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + o.uvOutDistTex = CUSTOM_TRANSFORM_TEX(v.uv, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + o.uvDistTex = CUSTOM_TRANSFORM_TEX(v.uv, _DistortTex_ScaleAndTiling); + #endif + + o.normalWS = -GetViewForwardDir(); + o.tangentWS = TransformObjectToWorldDir(v.tangent.xyz); + o.bitangentWS = cross(o.normalWS, o.tangentWS) * v.tangent.w; + + return o; +} + +#endif //ALLIN1SPRITESHADER_2DRENDERER_NORMALSRENDERINGVERTEXPASS \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingVertexPass.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingVertexPass.hlsl.meta new file mode 100644 index 0000000..f4fcd05 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingVertexPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: dd224f68ca07bc8428b37ddc8044f25b +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_NormalsRenderingVertexPass.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl new file mode 100644 index 0000000..0e21a36 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl @@ -0,0 +1,197 @@ +#ifndef ALLIN1SPRITESHADER_2DRENDERER_PROPERTIES +#define ALLIN1SPRITESHADER_2DRENDERER_PROPERTIES + +CBUFFER_START(UnityPerMaterial) + half4 /*_MainTex_ST, _MainTex_TexelSize,*/ _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha; + half _LitAmount; + half _NormalStrength; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half _RectSize; + + half _OffsetUvX, _OffsetUvY; + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + half _RoundWaveStrength, _RoundWaveSpeed; + + half _ZoomUvAmount; + + half4 _FadeBurnColor; /*_FadeTex_ST,*/ /*_FadeBurnTex_ST*/ + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition, _FadeBurnGlow; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half _HsvShift, _HsvSaturation, _HsvBright; + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + half _PixelateSize; + + half _NegativeAmount; + + half _ColorRampLuminosity, _ColorRampBlend; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _AlphaCutoffValue; + + half _AlphaRoundThreshold; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + half _Contrast, _Brightness; + + //half4 _OverlayTex_ST; + float4 _OverlayTex_ScaleAndTiling; + float4 _OverlayColor; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + float _RandomSeed; +CBUFFER_END + + +#define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw +#define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb +#define DECLARE_TEX_AND_SAMPLER(texName) \ + TEXTURE2D(texName);\ + SAMPLER(sampler##texName); + + +DECLARE_TEX_AND_SAMPLER(_MainTex) +DECLARE_TEX_AND_SAMPLER(_MaskTex) +DECLARE_TEX_AND_SAMPLER(_NormalMap) + +#if FADE_ON + DECLARE_TEX_AND_SAMPLER(_FadeTex) + DECLARE_TEX_AND_SAMPLER(_FadeBurnTex) +#endif + +#if GLOW_ON + DECLARE_TEX_AND_SAMPLER(_GlowTex) + //sampler2D _GlowTex; +#endif + +#if OUTTEX_ON + DECLARE_TEX_AND_SAMPLER(_OutlineTex) +#endif + +#if OUTDIST_ON + DECLARE_TEX_AND_SAMPLER(_OutlineDistortTex) + //sampler2D _OutlineDistortTex; +#endif + +#if DISTORT_ON + DECLARE_TEX_AND_SAMPLER(_DistortTex) + //sampler2D _DistortTex; +#endif + +#if COLORSWAP_ON + DECLARE_TEX_AND_SAMPLER(_ColorSwapTex) +#endif + +#if COLORRAMP_ON + DECLARE_TEX_AND_SAMPLER(_ColorRampTex) + DECLARE_TEX_AND_SAMPLER(_ColorRampTexGradient) +#endif + +#if SHINE_ON + DECLARE_TEX_AND_SAMPLER(_ShineMask) +#endif + +#if OVERLAY_ON + DECLARE_TEX_AND_SAMPLER(_OverlayTex) +#endif + + + +#endif //ALLIN1SPRITESHADER_2DRENDERER_PROPERTIES \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl.meta new file mode 100644 index 0000000..62556e9 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 2f5083985f9a1da43a7ce65b4add999a +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Properties.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl new file mode 100644 index 0000000..d22aefb --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl @@ -0,0 +1,76 @@ +#ifndef ALLIN1SPRITESHADER_2DRENDERER_SHADERFEATURES +#define ALLIN1SPRITESHADER_2DRENDERER_SHADERFEATURES + +#pragma shader_feature_local GLOWLIGHT_ON +#pragma shader_feature_local GLOW_ON +#pragma shader_feature_local FADE_ON +#pragma shader_feature_local OUTBASE_ON +#pragma shader_feature_local ONLYOUTLINE_ON +#pragma shader_feature_local GRADIENT_ON +#pragma shader_feature_local GRADIENT2COL_ON +#pragma shader_feature_local RADIALGRADIENT_ON +#pragma shader_feature_local COLORSWAP_ON +#pragma shader_feature_local HSV_ON +#pragma shader_feature_local CHANGECOLOR_ON +#pragma shader_feature_local CHANGECOLOR2_ON +#pragma shader_feature_local CHANGECOLOR3_ON +#pragma shader_feature_local COLORRAMP_ON +#pragma shader_feature_local GRADIENTCOLORRAMP_ON +#pragma shader_feature_local HITEFFECT_ON +#pragma shader_feature_local NEGATIVE_ON +#pragma shader_feature_local PIXELATE_ON +#pragma shader_feature_local GREYSCALE_ON +#pragma shader_feature_local POSTERIZE_ON +#pragma shader_feature_local BLUR_ON +#pragma shader_feature_local MOTIONBLUR_ON +#pragma shader_feature_local GHOST_ON +#pragma shader_feature_local ALPHAOUTLINE_ON +#pragma shader_feature_local INNEROUTLINE_ON +#pragma shader_feature_local ONLYINNEROUTLINE_ON +#pragma shader_feature_local HOLOGRAM_ON +#pragma shader_feature_local CHROMABERR_ON +#pragma shader_feature_local GLITCH_ON +#pragma shader_feature_local FLICKER_ON +#pragma shader_feature_local SHADOW_ON +#pragma shader_feature_local SHINE_ON +#pragma shader_feature_local CONTRAST_ON +#pragma shader_feature_local OVERLAY_ON +#pragma shader_feature_local OVERLAYMULT_ON +#pragma shader_feature_local ALPHACUTOFF_ON +#pragma shader_feature_local ALPHAROUND_ON +#pragma shader_feature_local DOODLE_ON +#pragma shader_feature_local WIND_ON +#pragma shader_feature_local WAVEUV_ON +#pragma shader_feature_local ROUNDWAVEUV_ON +#pragma shader_feature_local RECTSIZE_ON +#pragma shader_feature_local OFFSETUV_ON +#pragma shader_feature_local CLIPPING_ON +#pragma shader_feature_local RADIALCLIPPING_ON +#pragma shader_feature_local TEXTURESCROLL_ON +#pragma shader_feature_local ZOOMUV_ON +#pragma shader_feature_local DISTORT_ON +#pragma shader_feature_local WARP_ON +#pragma shader_feature_local TWISTUV_ON +#pragma shader_feature_local ROTATEUV_ON +#pragma shader_feature_local POLARUV_ON +#pragma shader_feature_local FISHEYE_ON +#pragma shader_feature_local PINCH_ON +#pragma shader_feature_local SHAKEUV_ON + +#pragma shader_feature_local GLOWTEX_ON +#pragma shader_feature_local OUTTEX_ON +#pragma shader_feature_local OUTDIST_ON +#pragma shader_feature_local OUTBASE8DIR_ON +#pragma shader_feature_local OUTBASEPIXELPERF_ON +#pragma shader_feature_local COLORRAMPOUTLINE_ON +#pragma shader_feature_local GREYSCALEOUTLINE_ON +#pragma shader_feature_local POSTERIZEOUTLINE_ON +#pragma shader_feature_local BLURISHD_ON +#pragma shader_feature_local MANUALWIND_ON +#pragma shader_feature_local ATLAS_ON +#pragma shader_feature_local PREMULTIPLYALPHA_ON + +#pragma shader_feature_local BILBOARD_ON +#pragma shader_feature_local BILBOARDY_ON + +#endif //ALLIN1SPRITESHADER_2DRENDERER_SHADERFEATURES \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl.meta new file mode 100644 index 0000000..9722586 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: fa43e9272d7e9da4895de72a2c8e0331 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_ShaderFeatures.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl new file mode 100644 index 0000000..653e936 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl @@ -0,0 +1,63 @@ +#ifndef ALLIN1SPRITESHADER_2DRENDERER_STRUCTS +#define ALLIN1SPRITESHADER_2DRENDERER_STRUCTS + +struct Attributes +{ + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half4 color : COLOR; + + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct v2f +{ + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + half4 color : COLOR; + float2 lightingUV : TEXCOORD1; + #if OUTTEX_ON + half2 uvOutTex : TEXCOORD2; + #endif + #if OUTDIST_ON + half2 uvOutDistTex : TEXCOORD3; + #endif + #if DISTORT_ON + half2 uvDistTex : TEXCOORD4; + #endif + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO +}; + +struct VertexDataNormalsPass +{ + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half4 color : COLOR; + half4 tangent : TANGENT; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct FragmentDataNormalsPass +{ + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + half4 color : COLOR; + half3 normalWS : TEXCOORD1; + half3 tangentWS : TEXCOORD2; + half3 bitangentWS : TEXCOORD3; + #if OUTTEX_ON + half2 uvOutTex : TEXCOORD4; + #endif + #if OUTDIST_ON + half2 uvOutDistTex : TEXCOORD5; + #endif + #if DISTORT_ON + half2 uvDistTex : TEXCOORD6; + #endif + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO +}; + + +#endif //ALLIN1SPRITESHADER_2DRENDERER_STRUCTS \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl.meta new file mode 100644 index 0000000..091d542 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 588186a477d7f5a469575ff210c49efa +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_Structs.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_VertexPass.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_VertexPass.hlsl new file mode 100644 index 0000000..3afdff1 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_VertexPass.hlsl @@ -0,0 +1,78 @@ +#ifndef ALLIN1SPRITESHADER_2DRENDERER_VERTEXPASS +#define ALLIN1SPRITESHADER_2DRENDERER_VERTEXPASS + +v2f CombinedShapeLightVertex(Attributes v) +{ + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + v2f o; + + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + half3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + #if UNITY_VERSION >= 60000000 + localPos.xy *= unity_SpriteProps.xy; + #endif + o.vertex = TransformObjectToHClip(localPos); + #else + half3 localPos = v.vertex.xyz; + #if UNITY_VERSION >= 60000000 + localPos.xy *= unity_SpriteProps.xy; + #endif + o.vertex = TransformObjectToHClip(localPos); + #endif + + o.uv = /*TRANSFORM_TEX(v.uv, _MainTex);*/v.uv * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + o.color = v.color; + #if UNITY_VERSION >= 60000000 + o.color *= unity_SpriteColor; + #endif + + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + #if POLARUV_ON + o.uv = v.uv - center; + #endif + + #if ROTATEUV_ON + half2 uvC = v.uv; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + o.uv = mul(rot, uvC); + o.uv += center; + #endif + + #if OUTTEX_ON + o.uvOutTex = CUSTOM_TRANSFORM_TEX(v.uv, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + o.uvOutDistTex = CUSTOM_TRANSFORM_TEX(v.uv, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + o.uvDistTex = CUSTOM_TRANSFORM_TEX(v.uv, _DistortTex_ScaleAndTiling); + #endif + + half4 clipVertex = o.vertex / o.vertex.w; + o.lightingUV = ComputeScreenPos(clipVertex).xy; + + return o; +} + +#endif //ALLIN1SPRITESHADER_2DRENDERER_VERTEXPASS \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_VertexPass.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_VertexPass.hlsl.meta new file mode 100644 index 0000000..ac7fdb9 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_VertexPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: a3d20933a82e6e5458ed3502ae2dbebb +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/2DRenderer/AllIn1SpriteShader_2DRenderer_VertexPass.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_CommonFunctions.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_CommonFunctions.hlsl new file mode 100644 index 0000000..075c0a6 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_CommonFunctions.hlsl @@ -0,0 +1,76 @@ +#ifndef ALLIN1SPRITESHADERSRP_COMMONFUNCTIONS +#define ALLIN1SPRITESHADERSRP_COMMONFUNCTIONS + +//Prevent Unity warnings that are not relevant for this shader------------------- +#pragma warning (disable : 3571) // pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them +#pragma warning (disable : 4008) // floating point division by zero +#pragma warning (disable : 3206) // implicit truncation of vector type +//BLURS------------------------------------------------------------------------- +half4 Blur(half2 uv, Texture2D source, SamplerState texSampler, half Intensity) +{ + const half2 texelSize = 1.0 / _ScreenParams.xy; + const half4 color = SAMPLE_TEXTURE2D(source, texSampler, uv); + const half2 offset = Intensity * texelSize; + + half4 accumulatedColor = color; + half accumulatedWeight = 1.0; + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + const half2 sampleUV = uv + half2(x, y) * offset; + const half4 sampleColor = SAMPLE_TEXTURE2D(source, texSampler, sampleUV); + + accumulatedColor += sampleColor; + accumulatedWeight += 1.0; + } + } + + half4 blurredColor = accumulatedColor / accumulatedWeight; + return blurredColor; +} + +half BlurHD_G(half bhqp, half x) +{ + return exp(-(x * x) / (2.0 * bhqp * bhqp)); +} +half4 BlurHD(half2 uv, Texture2D source, SamplerState texSampler, half BlurAmount, half xScale, half yScale) +{ + int iterations = 16; + int halfIterations = iterations / 2; + half sigmaX = 0.1 + BlurAmount * 0.5; + half sigmaY = sigmaX; + half total = 0.0; + half4 ret = half4(0, 0, 0, 0); + for (int iy = 0; iy < iterations; ++iy) + { + half fy = BlurHD_G(sigmaY, half(iy) -half(halfIterations)); + half offsetY = half(iy - halfIterations) * 0.00390625 * xScale; + for (int ix = 0; ix < iterations; ++ix) + { + half fx = BlurHD_G(sigmaX, half(ix) - half(halfIterations)); + half offsetX = half(ix - halfIterations) * 0.00390625 * yScale; + total += fx * fy; + ret += SAMPLE_TEXTURE2D(source, texSampler, uv + half2(offsetX, offsetY)) * fx * fy; + } + } + return ret / total; +} +//----------------------------------------------------------------------- +half rand(half2 seed, half offset) { + return (frac(sin(dot(seed, half2(12.9898, 78.233))) * 43758.5453) + offset) % 1.0; +} + +half rand2(half2 seed, half offset, half speed) { + return (frac(sin(dot(seed * floor(50 + (_Time.x % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; +} + +half rand2CustomTime(half2 seed, half offset, half customTime, half speed) { + return (frac(sin(dot(seed * floor(50 + (customTime % 1.0) * 12. * speed), half2(127.1, 311.7))) * 43758.5453123) + offset) % 1.0; +} +//----------------------------------------------------------------------- +half RemapFloat(half inValue, half inMin, half inMax, half outMin, half outMax){ + return outMin + (inValue - inMin) * (outMax - outMin) / (inMax - inMin); +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_CommonFunctions.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_CommonFunctions.hlsl.meta new file mode 100644 index 0000000..c10c66d --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_CommonFunctions.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 13806bf35145bcd46a31f91837eda276 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_CommonFunctions.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_FragmentPass.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_FragmentPass.hlsl new file mode 100644 index 0000000..7c7801f --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_FragmentPass.hlsl @@ -0,0 +1,573 @@ +#ifndef ALLIN1SPRITESHADERSRP_FRAGMENTPASS +#define ALLIN1SPRITESHADERSRP_FRAGMENTPASS + +half4 frag(v2f i) : SV_Target +{ + UNITY_SETUP_INSTANCE_ID(i); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + + //half randomSeed = UNITY_ACCESS_INSTANCED_PROP(Props, _RandomSeed); + float randomSeed = _RandomSeed; + + float texWidth; + float texHeight; + _MainTex.GetDimensions(texWidth, texHeight); + float4 texelSize = float4(1.0 / texWidth, 1 / texHeight, texWidth, texHeight); + + float2 uvRect = i.uv; + half2 center = half2(0.5, 0.5); +#if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + uvRect = half2((i.uv.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uv.y - _MinYUV) / (_MaxYUV - _MinYUV)); +#endif + half2 centerTiled = half2(center.x * _MainTex_ScaleAndTiling.x, center.y * _MainTex_ScaleAndTiling.y); + +#if CLIPPING_ON + half2 tiledUv = half2(i.uv.x / _MainTex_ScaleAndTiling.x, i.uv.y / _MainTex_ScaleAndTiling.y); +#if ATLAS_ON + tiledUv = half2((tiledUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); +#endif + clip((1 - _ClipUvUp) - tiledUv.y); + clip(tiledUv.y - _ClipUvDown); + clip((1 - _ClipUvRight) - tiledUv.x); + clip(tiledUv.x - _ClipUvLeft); +#endif + +#if RADIALCLIPPING_ON + half2 tiledUv2 = half2(i.uv.x / _MainTex_ScaleAndTiling.x, i.uv.y / _MainTex_ScaleAndTiling.y); +#if ATLAS_ON + tiledUv2 = half2((tiledUv2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUv2.y - _MinYUV) / (_MaxYUV - _MinYUV)); +#endif + half startAngle = _RadialStartAngle - _RadialClip; + half endAngle = _RadialStartAngle + _RadialClip2; + half offset0 = clamp(0, 360, startAngle + 360); + half offset360 = clamp(0, 360, endAngle - 360); + half2 atan2Coord = half2(lerp(-1, 1, tiledUv2.x), lerp(-1, 1, tiledUv2.y)); + half atanAngle = atan2(atan2Coord.y, atan2Coord.x) * 57.3; // angle in degrees + if(atanAngle < 0) atanAngle = 360 + atanAngle; + if(atanAngle >= startAngle && atanAngle <= endAngle) discard; + if(atanAngle <= offset360) discard; + if(atanAngle >= offset0) discard; +#endif + +#if TEXTURESCROLL_ON && ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs(((_Time.y + randomSeed) * _TextureScrollXSpeed) + uvRect.x) % 1)), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(((_Time.y + randomSeed) * _TextureScrollYSpeed) + uvRect.y) % 1))); +#endif + +#if OFFSETUV_ON +#if ATLAS_ON + i.uv = half2(_MinXUV + ((_MaxXUV - _MinXUV) * (abs((_OffsetUvX + uvRect.x) % 1))), + _MinYUV + ((_MaxYUV - _MinYUV) * (abs(_OffsetUvY + uvRect.y) % 1))); +#else + i.uv += half2(_OffsetUvX, _OffsetUvY); +#endif +#endif + +#if POLARUV_ON + i.uv = half2(atan2(i.uv.y, i.uv.x) / (2.0f * 3.141592653589f), length(i.uv)); + i.uv *= _MainTex_ScaleAndTiling.xy; +#endif + +#if TWISTUV_ON +#if ATLAS_ON + _TwistUvPosX = ((_MaxXUV - _MinXUV) * _TwistUvPosX) + _MinXUV; + _TwistUvPosY = ((_MaxYUV - _MinYUV) * _TwistUvPosY) + _MinYUV; +#endif + half2 tempUv = i.uv - half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + _TwistUvRadius *= (_MainTex_ScaleAndTiling.x + _MainTex_ScaleAndTiling.y) / 2; + half percent = (_TwistUvRadius - length(tempUv)) / _TwistUvRadius; + half theta = percent * percent * (2.0 * sin(_TwistUvAmount)) * 8.0; + half s = sin(theta); + half c = cos(theta); + half beta = max(sign(_TwistUvRadius - length(tempUv)), 0.0); + tempUv = half2(dot(tempUv, half2(c, -s)), dot(tempUv, half2(s, c))) * beta + tempUv * (1 - beta); + tempUv += half2(_TwistUvPosX * _MainTex_ScaleAndTiling.x, _TwistUvPosY * _MainTex_ScaleAndTiling.y); + i.uv = tempUv; +#endif + +#if FISHEYE_ON + half bind = length(centerTiled); + half2 dF = i.uv - centerTiled; + half dFlen = length(dF); + half fishInt = (3.14159265359 / bind) * (_FishEyeUvAmount + 0.001); + i.uv = centerTiled + (dF / (max(0.0001, dFlen))) * tan(dFlen * fishInt) * bind / tan(bind * fishInt); +#endif + +#if PINCH_ON + half2 dP = i.uv - centerTiled; + half pinchInt = (3.141592 / length(centerTiled)) * (-_PinchUvAmount + 0.001); + i.uv = centerTiled + normalize(dP) * atan(length(dP) * -pinchInt * 10.0) * 0.5 / atan(-pinchInt * 5); +#endif + +#if ZOOMUV_ON + i.uv -= centerTiled; + i.uv = i.uv * _ZoomUvAmount; + i.uv += centerTiled; +#endif + +#if DOODLE_ON + half2 uvCopy = uvRect; + _HandDrawnSpeed = (floor((_Time.x + randomSeed) * 20 * _HandDrawnSpeed) / _HandDrawnSpeed) * _HandDrawnSpeed; + uvCopy.x = sin((uvCopy.x * _HandDrawnAmount + _HandDrawnSpeed) * 4); + uvCopy.y = cos((uvCopy.y * _HandDrawnAmount + _HandDrawnSpeed) * 4); + i.uv = lerp(i.uv, i.uv + uvCopy, 0.0005 * _HandDrawnAmount); +#endif + +#if SHAKEUV_ON + half xShake = sin((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvX; + half yShake = cos((_Time.x + randomSeed) * _ShakeUvSpeed * 50) * _ShakeUvY; + i.uv += half2(xShake * 0.012, yShake * 0.01); +#endif + +#if RECTSIZE_ON + i.uv = i.uv.xy * (_RectSize).xx + (((-_RectSize * 0.5) + 0.5)).xx; +#endif + +#if DISTORT_ON +#if ATLAS_ON + i.uvDistTex.x = i.uvDistTex.x * (1 / (_MaxXUV - _MinXUV)); + i.uvDistTex.y = i.uvDistTex.y * (1 / (_MaxYUV - _MinYUV)); +#endif + i.uvDistTex.x += ((_Time.x + randomSeed) * _DistortTexXSpeed) % 1; + i.uvDistTex.y += ((_Time.x + randomSeed) * _DistortTexYSpeed) % 1; + half distortAmnt = (SAMPLE_TEXTURE2D(_DistortTex, sampler_DistortTex, i.uvDistTex).r - 0.5) * 0.2 * _DistortAmount; + i.uv.x += distortAmnt; + i.uv.y += distortAmnt; +#endif + +#if WARP_ON + half2 warpUv = half2(i.uv.x / _MainTex_ScaleAndTiling.x, i.uv.y / _MainTex_ScaleAndTiling.y); +#if ATLAS_ON + warpUv = half2((warpUv.x - _MinXUV) / (_MaxXUV - _MinXUV), (warpUv.y - _MinYUV) / (_MaxYUV - _MinYUV)); +#endif + const float tau = 6.283185307179586; + float xWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.x * tau / _WarpScale; + float yWarp = (_Time.y + randomSeed) * _WarpSpeed + warpUv.y * tau / _WarpScale; + float2 warp = float2(sin(xWarp), sin(yWarp)) * _WarpStrength; + i.uv += warp; +#endif + +#if WAVEUV_ON + float2 uvWave = half2(_WaveX * _MainTex_ScaleAndTiling.x, _WaveY * _MainTex_ScaleAndTiling.y) - i.uv; + uvWave %= 1; +#if ATLAS_ON + uvWave = half2(_WaveX, _WaveY) - uvRect; +#endif + uvWave.x *= _ScreenParams.x / _ScreenParams.y; + float waveTime = _Time.y + randomSeed; + float angWave = (sqrt(dot(uvWave, uvWave)) * _WaveAmount) - ((waveTime * _WaveSpeed)); + i.uv = i.uv + uvWave * sin(angWave) * (_WaveStrength / 1000.0); +#endif + +#if ROUNDWAVEUV_ON + half xWave = ((0.5 * _MainTex_ScaleAndTiling.x) - uvRect.x); + half yWave = ((0.5 * _MainTex_ScaleAndTiling.y) - uvRect.y) * (texelSize.w / texelSize.z); + half ripple = -sqrt(xWave*xWave + yWave* yWave); + i.uv += (sin((ripple + (_Time.y + randomSeed) * (_RoundWaveSpeed/10.0)) / 0.015) * (_RoundWaveStrength/10.0)) % 1; +#endif + +#if WIND_ON + half windOffset = sin((_Time.x + randomSeed) * _GrassSpeed * 10); + half2 windCenter = half2(0.5, 0.1); +#if ATLAS_ON + windCenter.x = ((_MaxXUV - _MinXUV) * windCenter.x) + _MinXUV; + windCenter.y = ((_MaxYUV - _MinYUV) * windCenter.y) + _MinYUV; +#endif +#if !MANUALWIND_ON + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * windOffset), uvRect.y)), 1); +#else + i.uv.x = fmod(abs(lerp(i.uv.x, i.uv.x + (_GrassWind * 0.01 * _GrassManualAnim), uvRect.y)), 1); + windOffset = _GrassManualAnim; +#endif + half2 delta = i.uv - windCenter; + half delta2 = dot(delta.xy, delta.xy); + half2 delta_offset = delta2 * windOffset; + i.uv = i.uv + half2(delta.y, -delta.x) * delta_offset * _GrassRadialBend; +#endif + +#if TEXTURESCROLL_ON && !ATLAS_ON + i.uv.x += ((_Time.y + randomSeed) * _TextureScrollXSpeed) % 1; + i.uv.y += ((_Time.y + randomSeed) * _TextureScrollYSpeed) % 1; +#endif + +#if PIXELATE_ON + half aspectRatio = texelSize.x / texelSize.y; + half2 pixelSize = float2(_PixelateSize, _PixelateSize * aspectRatio); + i.uv = floor(i.uv * pixelSize) / pixelSize; +#endif + + half4 col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv); + half originalAlpha = col.a; + col *= i.color; +#if PREMULTIPLYALPHA_ON + col.rgb *= col.a; +#endif + +#if GLITCH_ON + half2 uvGlitch = uvRect; + uvGlitch.y -= 0.5; + half lineNoise = pow(rand2(floor(uvGlitch * half2(24., 19.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0) * _GlitchAmount + * pow(rand2(floor(uvGlitch * half2(38., 14.) * _GlitchSize) * 4.0, randomSeed, _GlitchSpeed), 3.0); + col = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + half2(lineNoise * 0.02 * rand2(half2(2.0, 1), randomSeed, _GlitchSpeed), 0)) * i.color; +#endif + +#if CHROMABERR_ON + half4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + half2(_ChromAberrAmount/10, 0)) * i.color; + half4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + half2(-_ChromAberrAmount/10, 0)) * i.color; + col = half4(r.r * r.a, col.g, b.b * b.a, max(max(r.a, b.a) * _ChromAberrAlpha, col.a)); +#endif + +#if BLUR_ON +#if ATLAS_ON +#if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, sampler_MainTex, _BlurIntensity, (_MaxXUV - _MinXUV), (_MaxYUV - _MinYUV)) * i.color; +#else + col = Blur(i.uv, _MainTex, sampler_MainTex, _BlurIntensity * (_MaxXUV - _MinXUV)) * i.color; +#endif +#else +#if !BLURISHD_ON + col = BlurHD(i.uv, _MainTex, sampler_MainTex, _BlurIntensity, 1, 1) * i.color; +#else + col = Blur(i.uv, _MainTex, sampler_MainTex, _BlurIntensity) * i.color; +#endif +#endif +#endif + +#if MOTIONBLUR_ON + _MotionBlurAngle = _MotionBlurAngle * 3.1415926; +#define rot(n) mul(n, half2x2(cos(_MotionBlurAngle), -sin(_MotionBlurAngle), sin(_MotionBlurAngle), cos(_MotionBlurAngle))) + _MotionBlurDist = _MotionBlurDist * 0.005; +#if ATLAS_ON + _MotionBlurDist *= (_MaxXUV - _MinXUV); +#endif + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + rot(half2(-_MotionBlurDist, -_MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + rot(half2(-_MotionBlurDist * 2, -_MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + rot(half2(-_MotionBlurDist * 3, -_MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + rot(half2(-_MotionBlurDist * 4, -_MotionBlurDist * 4))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + rot(half2(_MotionBlurDist, _MotionBlurDist))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + rot(half2(_MotionBlurDist * 2, _MotionBlurDist * 2))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + rot(half2(_MotionBlurDist * 3, _MotionBlurDist * 3))); + col.rgb += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + rot(half2(_MotionBlurDist * 4, _MotionBlurDist * 4))); + col.rgb = col.rgb / 9; +#endif + +#if NEGATIVE_ON + col.rgb = lerp(col.rgb, 1 - col.rgb, _NegativeAmount); +#endif + + half luminance = 0; +#if GREYSCALE_ON && !GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); +#endif + +#if GHOST_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 ghostResult; + ghostResult.a = saturate(luminance - _GhostTransparency) * col.a; + ghostResult.rgb = col.rgb * (luminance + _GhostColorBoost); + col = lerp(col, ghostResult, _GhostBlend); +#endif + +#if INNEROUTLINE_ON + half3 innerT = abs(GET_PIXEL(0, _InnerOutlineThickness, i.uv, _MainTex, texelSize) - GET_PIXEL(0, -_InnerOutlineThickness, i.uv, _MainTex, texelSize)); + innerT += abs(GET_PIXEL(_InnerOutlineThickness, 0, i.uv, _MainTex, texelSize) - GET_PIXEL(-_InnerOutlineThickness, 0, i.uv, _MainTex, texelSize)); +#if !ONLYINNEROUTLINE_ON + innerT = (innerT / 2.0) * col.a * _InnerOutlineAlpha; + col.rgb += length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; +#else + innerT *= col.a * _InnerOutlineAlpha; + col.rgb = length(innerT) * _InnerOutlineColor.rgb * _InnerOutlineGlow; + col.a = step(0.3, col.r+col.g+col.b); +#endif +#endif + +#if HITEFFECT_ON + col.rgb = lerp(col.rgb, _HitEffectColor.rgb * _HitEffectGlow, _HitEffectBlend); +#endif + +#if GRADIENT_ON + half2 tiledUvGrad = half2(uvRect.x / _MainTex_ScaleAndTiling.x, uvRect.y / _MainTex_ScaleAndTiling.y); +#if GRADIENT2COL_ON + _GradTopRightCol = _GradTopLeftCol; + _GradBotRightCol = _GradBotLeftCol; +#endif +#if RADIALGRADIENT_ON + half radialDist = 1 - length(tiledUvGrad - half2(0.5, 0.5)); + radialDist *= (texelSize.w / texelSize.z); + radialDist = saturate(_GradBoostX * radialDist); + half4 gradientResult = lerp(_GradTopLeftCol, _GradBotLeftCol, radialDist); +#else + half gradXLerpFactor = saturate(pow(tiledUvGrad.x, _GradBoostX)); + half4 gradientResult = lerp(lerp(_GradBotLeftCol, _GradBotRightCol, gradXLerpFactor), + lerp(_GradTopLeftCol, _GradTopRightCol, gradXLerpFactor), saturate(pow(tiledUvGrad.y, _GradBoostY))); +#endif + gradientResult = lerp(col, gradientResult, _GradBlend); + col.rgb = gradientResult.rgb * col.a; + col.a *= gradientResult.a; +#endif + +#if CONTRAST_ON + col.rgb = (col.rgb - float3(0.5, 0.5, 0.5)) * _Contrast + float3(0.5, 0.5, 0.5); + col.rgb += _Brightness; +#endif + +#if COLORSWAP_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + half4 swapMask = SAMPLE_TEXTURE2D(_ColorSwapTex, sampler_ColorSwapTex, i.uv); + swapMask.rgb *= swapMask.a; + half3 redSwap = _ColorSwapRed * swapMask.r * saturate(luminance + _ColorSwapRedLuminosity); + half3 greenSwap = _ColorSwapGreen * swapMask.g * saturate(luminance + _ColorSwapGreenLuminosity); + half3 blueSwap = _ColorSwapBlue * swapMask.b * saturate(luminance + _ColorSwapBlueLuminosity); + swapMask.rgb = col.rgb * saturate(1 - swapMask.r - swapMask.g - swapMask.b); + col.rgb = lerp(col.rgb, swapMask.rgb + redSwap + greenSwap + blueSwap, _ColorSwapBlend); +#endif + +#if COLORRAMP_ON && !COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); +#if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTexGradient, sampler_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); +#else + col.rgb = lerp(col.rgb, SAMPLE_TEXTURE2D(_ColorRampTex, sampler_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); +#endif +#endif + +#if CHANGECOLOR_ON + float3 currChangeColor = saturate(col.rgb); + luminance = 0.3 * currChangeColor.r + 0.59 * currChangeColor.g + 0.11 * currChangeColor.b; + luminance = saturate(luminance + _ColorChangeLuminosity); + half3 dif = abs(currChangeColor - _ColorChangeTarget.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance), 0.0)); +#if CHANGECOLOR2_ON + dif = abs(currChangeColor - _ColorChangeTarget2.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol2.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance2), 0.0)); +#endif +#if CHANGECOLOR3_ON + dif = abs(currChangeColor - _ColorChangeTarget3.rgb); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _ColorChangeNewCol3.rgb, + max(sign(1 - saturate(dif.x + dif.y + dif.z) - _ColorChangeTolerance3), 0.0)); +#endif +#endif + +#if POSTERIZE_ON && !POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); +#endif + +#if HSV_ON + half3 resultHsv = half3(col.rgb); + half cosHsv = _HsvBright * _HsvSaturation * cos(_HsvShift * 3.14159265 / 180); + half sinHsv = _HsvBright * _HsvSaturation * sin(_HsvShift * 3.14159265 / 180); + resultHsv.x = (.299 * _HsvBright + .701 * cosHsv + .168 * sinHsv) * col.x + + (.587 * _HsvBright - .587 * cosHsv + .330 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv - .497 * sinHsv) * col.z; + resultHsv.y = (.299 * _HsvBright - .299 * cosHsv - .328 * sinHsv) *col.x + + (.587 * _HsvBright + .413 * cosHsv + .035 * sinHsv) * col.y + + (.114 * _HsvBright - .114 * cosHsv + .292 * sinHsv) * col.z; + resultHsv.z = (.299 * _HsvBright - .3 * cosHsv + 1.25 * sinHsv) * col.x + + (.587 * _HsvBright - .588 * cosHsv - 1.05 * sinHsv) * col.y + + (.114 * _HsvBright + .886 * cosHsv - .203 * sinHsv) * col.z; + col.rgb = resultHsv; +#endif + +#if OVERLAY_ON + half2 overlayUvs = uvRect; + overlayUvs.x += ((_Time.y + randomSeed) * _OverlayTextureScrollXSpeed) % 1; + overlayUvs.y += ((_Time.y + randomSeed) * _OverlayTextureScrollYSpeed) % 1; + half4 overlayCol = SAMPLE_TEXTURE2D(_OverlayTex, sampler_OverlayTex, CUSTOM_TRANSFORM_TEX(overlayUvs, _OverlayTex_ScaleAndTiling)); + overlayCol.rgb *= _OverlayColor.rgb * _OverlayGlow; +#if !OVERLAYMULT_ON + overlayCol.rgb *= overlayCol.a * _OverlayColor.rgb * _OverlayColor.a * _OverlayBlend; + col.rgb += overlayCol.rgb; +#else + overlayCol.a *= _OverlayColor.a; + col = lerp(col, col * overlayCol, _OverlayBlend); +#endif +#endif + + //OUTLINE------------------------------------------------------------- +#if OUTBASE_ON + #if OUTBASEPIXELPERF_ON + //half2 destUv = _OutlinePixelWidth / unity_SpriteProps.w; + half2 destUv = half2(_OutlinePixelWidth * texelSize.x, _OutlinePixelWidth * texelSize.y); + #else + //half2 destUv = _OutlinePixelWidth / unity_SpriteProps.w; + half2 destUv = half2(_OutlineWidth * texelSize.x * 200, _OutlineWidth * texelSize.y * 200); + #endif + + #if OUTDIST_ON + half2 uvOutDist = uvRect; + uvOutDist.x += ((_Time.x + randomSeed) * _OutlineDistortTexXSpeed) % 1; + uvOutDist.y += ((_Time.x + randomSeed) * _OutlineDistortTexYSpeed) % 1; + half outDistortAmnt = (SAMPLE_TEXTURE2D(_OutlineDistortTex, sampler_OutlineDistortTex, CUSTOM_TRANSFORM_TEX(uvOutDist, _OutlineDistortTex_ScaleAndTiling)).r - 0.5) * 0.2 * _OutlineDistortAmount; + destUv.x += outDistortAmnt; + destUv.y += outDistortAmnt; + #endif + + half spriteLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + half2(destUv.x, 0)).a; + half spriteRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv - half2(destUv.x, 0)).a; + half spriteBottom = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + half2(0, destUv.y)).a; + half spriteTop = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv - half2(0, destUv.y)).a; + + half result = spriteLeft + spriteRight + spriteBottom + spriteTop; + + #if OUTBASE8DIR_ON + half spriteTopLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + half2(destUv.x, destUv.y)).a; + half spriteTopRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + half2(-destUv.x, destUv.y)).a; + half spriteBotLeft = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + half2(destUv.x, -destUv.y)).a; + half spriteBotRight = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + half2(-destUv.x, -destUv.y)).a; + + result = result + spriteTopLeft + spriteTopRight + spriteBotLeft + spriteBotRight; + #endif + + result = step(0.05, saturate(result)); + + #if OUTTEX_ON + i.uvOutTex.x += ((_Time.x + randomSeed) * _OutlineTexXSpeed) % 1; + i.uvOutTex.y += ((_Time.x + randomSeed) * _OutlineTexYSpeed) % 1; + #if ATLAS_ON + i.uvOutTex = half2((i.uvOutTex.x - _MinXUV) / (_MaxXUV - _MinXUV), (i.uvOutTex.y - _MinYUV) / (_MaxYUV - _MinYUV)); + #endif + half4 tempOutColor = SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, i.uvOutTex); + tempOutColor *= _OutlineColor; + _OutlineColor = tempOutColor; + #endif + + result *= (1 - originalAlpha) * _OutlineAlpha; + + half4 outline = _OutlineColor * i.color.a; + outline.rgb *= _OutlineGlow; + outline.a = result; + #if ONLYOUTLINE_ON + col = outline; + #else + col = lerp(col, outline, result); + #endif +#endif + //----------------------------------------------------------------------------- + +#if FADE_ON + half2 tiledUvFade1= CUSTOM_TRANSFORM_TEX(i.uv, _FadeTex_ScaleAndTiling); + half2 tiledUvFade2 = CUSTOM_TRANSFORM_TEX(i.uv, _FadeBurnTex_ScaleAndTiling); +#if ATLAS_ON + tiledUvFade1 = half2((tiledUvFade1.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade1.y - _MinYUV) / (_MaxYUV - _MinYUV)); + tiledUvFade2 = half2((tiledUvFade2.x - _MinXUV) / (_MaxXUV - _MinXUV), (tiledUvFade2.y - _MinYUV) / (_MaxYUV - _MinYUV)); +#endif + half fadeTemp = SAMPLE_TEXTURE2D(_FadeTex, sampler_FadeTex, tiledUvFade1).r; + half fade = smoothstep(_FadeAmount, _FadeAmount + _FadeBurnTransition, fadeTemp); + half fadeBurn = saturate(smoothstep(_FadeAmount - _FadeBurnWidth, _FadeAmount - _FadeBurnWidth + 0.1, fadeTemp) * _FadeAmount); + col.a *= fade; + _FadeBurnColor.rgb *= _FadeBurnGlow; + col += fadeBurn * SAMPLE_TEXTURE2D(_FadeBurnTex, sampler_FadeBurnTex, tiledUvFade2) * _FadeBurnColor * originalAlpha * (1 - col.a); +#endif + +#if SHADOW_ON + half shadowA = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + half2(_ShadowX, _ShadowY)).a; + half preMultShadowMask = 1 - (saturate(shadowA - col.a) * (1 - col.a)); + col.rgb *= 1 - ((shadowA - col.a) * (1 - col.a)); + col.rgb += (_ShadowColor * shadowA) * (1 - col.a); + col.a = max(shadowA * _ShadowAlpha * i.color.a, col.a); +#endif + +#if GLOW_ON + half4 emission; +#if GLOWTEX_ON + emission = SAMPLE_TEXTURE2D(_GlowTex, sampler_GlowTex, i.uv); +#else + emission = col; +#endif + col.rgb *= _GlowGlobal; + emission.rgb *= emission.a * col.a * _Glow * _GlowColor; + col.rgb += emission.rgb; +#endif + +#if COLORRAMP_ON && COLORRAMPOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _ColorRampLuminosity); +#if GRADIENTCOLORRAMP_ON + col.rgb = lerp(col.rgb, tex2D(_ColorRampTexGradient, half2(luminance, 0)).rgb, _ColorRampBlend); +#else + col.rgb = lerp(col.rgb, tex2D(_ColorRampTex, half2(luminance, 0)).rgb, _ColorRampBlend); +#endif +#endif + +#if GREYSCALE_ON && GREYSCALEOUTLINE_ON + luminance = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b; + luminance = saturate(luminance + _GreyscaleLuminosity); + col.rgb = lerp(col.rgb, half3(luminance, luminance, luminance) * _GreyscaleTintColor, _GreyscaleBlend); +#endif + +#if POSTERIZE_ON && POSTERIZEOUTLINE_ON + col.rgb = pow(col.rgb, _PosterizeGamma) * _PosterizeNumColors; + col.rgb = floor(col.rgb) / _PosterizeNumColors; + col.rgb = pow(col.rgb, 1.0 / _PosterizeGamma); +#endif + +#if SHINE_ON + half2 uvShine = uvRect; + half cosAngle = cos(_ShineRotate); + half sinAngle = sin(_ShineRotate); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvShine -= half2(0.5, 0.5); + uvShine = mul(rot, uvShine); + uvShine += half2(0.5, 0.5); + half shineMask = SAMPLE_TEXTURE2D(_ShineMask, sampler_ShineMask, i.uv).a; + half currentDistanceProjection = (uvShine.x + uvShine.y) / 2; + half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth); + col.rgb += col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0) + * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask; +#endif + +#if HOLOGRAM_ON + half totalHologram = _HologramStripesAmount + _HologramUnmodAmount; + half hologramYCoord = ((uvRect.y + (((_Time.x + randomSeed) % 1) * _HologramStripesSpeed)) % totalHologram) / totalHologram; + hologramYCoord = abs(hologramYCoord); + half alpha = RemapFloat(saturate(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0, 1.0, _HologramMinAlpha, saturate(_HologramMaxAlpha)); + half hologramMask = max(sign((_HologramUnmodAmount/totalHologram) - hologramYCoord), 0.0); + half4 hologramResult = col; + hologramResult.a *= lerp(alpha, 1, hologramMask); + hologramResult.rgb *= max(1, _HologramMaxAlpha * max(sign(hologramYCoord - (_HologramUnmodAmount/totalHologram)), 0.0)); + hologramMask = 1 - step(0.01,hologramMask); + hologramResult.rgb += hologramMask * _HologramStripeColor * col.a; + col = lerp(col, hologramResult, _HologramBlend); +#endif + +#if FLICKER_ON + col.a *= saturate(col.a * step(frac(0.05 + (_Time.w + randomSeed) * _FlickerFreq), 1 - _FlickerPercent) + _FlickerAlpha); +#endif + +col.a *= _Alpha; + +#if ALPHACUTOFF_ON + clip((1 - _AlphaCutoffValue) - (1 - col.a) - 0.01); +#endif + +#if ALPHAROUND_ON + col.a = step(_AlphaRoundThreshold, col.a); +#endif + +#if ALPHAOUTLINE_ON + half alphaOutlineRes = pow(1 - col.a, max(_AlphaOutlinePower, 0.0001)) * step(_AlphaOutlineMinAlpha, col.a) * _AlphaOutlineBlend; + col.rgb = lerp(col.rgb, _AlphaOutlineColor.rgb * _AlphaOutlineGlow, alphaOutlineRes); + col.a = lerp(col.a, 1, alphaOutlineRes > 1); +#endif + + col *= _Color; + #if !defined(HDRP_PASS) && UNITY_VERSION >= 60000000 + col *= unity_SpriteColor; + #endif + +#if FOG_ON + col = AllIn1MixFog(col, i.vertex, i.positionWS, i.fogCoord); +#endif + + return col; +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_FragmentPass.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_FragmentPass.hlsl.meta new file mode 100644 index 0000000..ce01e9c --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_FragmentPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: c219b648ae17310408a5f5ba5b099249 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_FragmentPass.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_HDRPHelper.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_HDRPHelper.hlsl new file mode 100644 index 0000000..afe85a6 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_HDRPHelper.hlsl @@ -0,0 +1,32 @@ +#ifndef ALLIN1SPRITESHADERSRP_HDRPHELPER +#define ALLIN1SPRITESHADERSRP_HDRPHELPER + +//fogCoord only used in URP. It's here to make both functions have the same parameters +float4 AllIn1MixFog(float4 inputColor, float4 clipPos, float3 positionWS, float fogCoord) +{ + float4 res = inputColor; + if (_FogEnabled) + { + PositionInputs posInput = GetPositionInput( + clipPos.xy, + _ScreenSize.zw, + clipPos.z, + clipPos.w, + positionWS, //In HDRP is RWS + 0 + ); + + float3 V = GetWorldSpaceNormalizeViewDir(positionWS); + + float3 fogColor; + float3 fogOpacity; + EvaluateAtmosphericScattering(posInput, V, fogColor, fogOpacity); + + res.rgb = (res.rgb * fogOpacity) + fogColor; + res.a *= (1 - fogOpacity); + } + + return res; +} + +#endif //ALLIN1SPRITESHADERSRP_HDRPHELPER \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_HDRPHelper.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_HDRPHelper.hlsl.meta new file mode 100644 index 0000000..fe30663 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_HDRPHelper.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: c2403e765aad6494d86eaaec9cdd5385 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_HDRPHelper.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Properties.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Properties.hlsl new file mode 100644 index 0000000..8d4673b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Properties.hlsl @@ -0,0 +1,191 @@ +#ifndef ALLIN1SPRITESHADERSRP_PROPERTIES +#define ALLIN1SPRITESHADERSRP_PROPERTIES + +CBUFFER_START(UnityPerMaterial) + half4 /*_MainTex_ST,*/ /*_MainTex_TexelSize,*/ _Color; + float4 _MainTex_ScaleAndTiling; + + half _Alpha; + + half _MinXUV, _MaxXUV, _MinYUV, _MaxYUV; + + half _RectSize; + + half _OffsetUvX, _OffsetUvY; + + half _ClipUvLeft, _ClipUvRight, _ClipUvUp, _ClipUvDown; + + half _RadialStartAngle, _RadialClip, _RadialClip2; + + half _TwistUvAmount, _TwistUvPosX, _TwistUvPosY, _TwistUvRadius; + + half _RotateUvAmount; + + half _FishEyeUvAmount; + + half _PinchUvAmount; + + half _HandDrawnAmount, _HandDrawnSpeed; + + half _ShakeUvSpeed, _ShakeUvX, _ShakeUvY; + + float _WaveAmount, _WaveSpeed, _WaveStrength, _WaveX, _WaveY; + + half _RoundWaveStrength, _RoundWaveSpeed; + + half _ZoomUvAmount; + + half4 _FadeBurnColor; /*_FadeTex_ST,*/ /*_FadeBurnTex_ST*/ + float4 _FadeTex_ScaleAndTiling, _FadeBurnTex_ScaleAndTiling; + half _FadeAmount, _FadeBurnWidth, _FadeBurnTransition, _FadeBurnGlow; + + half _TextureScrollXSpeed, _TextureScrollYSpeed; + + half4 _GlowColor; + half _Glow, _GlowGlobal; + + + half4 _OutlineColor; + half _OutlineAlpha, _OutlineGlow, _OutlineWidth; + int _OutlinePixelWidth; + + //half4 _OutlineTex_ST; + float4 _OutlineTex_ScaleAndTiling; + half _OutlineTexXSpeed, _OutlineTexYSpeed; + + //half4 _OutlineDistortTex_ST; + float4 _OutlineDistortTex_ScaleAndTiling; + half _OutlineDistortTexXSpeed, _OutlineDistortTexYSpeed, _OutlineDistortAmount; + + //half4 _DistortTex_ST; + float4 _DistortTex_ScaleAndTiling; + half _DistortTexXSpeed, _DistortTexYSpeed, _DistortAmount; + + half _WarpStrength, _WarpSpeed, _WarpScale; + + half _GrassSpeed, _GrassWind, _GrassManualAnim, _GrassRadialBend; + + half _GradBlend, _GradBoostX, _GradBoostY; + half4 _GradTopRightCol, _GradTopLeftCol, _GradBotRightCol, _GradBotLeftCol; + + half4 _ColorSwapRed, _ColorSwapGreen, _ColorSwapBlue; + half _ColorSwapRedLuminosity, _ColorSwapGreenLuminosity, _ColorSwapBlueLuminosity, _ColorSwapBlend; + + half _HsvShift, _HsvSaturation, _HsvBright; + + half4 _HitEffectColor; + half _HitEffectGlow, _HitEffectBlend; + + half _PixelateSize; + + half _NegativeAmount; + + half _ColorRampLuminosity, _ColorRampBlend; + + half _GreyscaleLuminosity, _GreyscaleBlend; + half4 _GreyscaleTintColor; + + half _PosterizeNumColors, _PosterizeGamma; + + half _BlurIntensity; + + half _MotionBlurAngle, _MotionBlurDist; + + half _GhostColorBoost, _GhostTransparency, _GhostBlend; + + half _AlphaOutlineGlow, _AlphaOutlinePower, _AlphaOutlineMinAlpha, _AlphaOutlineBlend; + half4 _AlphaOutlineColor; + + half _InnerOutlineThickness, _InnerOutlineAlpha, _InnerOutlineGlow; + half4 _InnerOutlineColor; + + half _HologramStripesAmount, _HologramMinAlpha, _HologramUnmodAmount, _HologramStripesSpeed, _HologramMaxAlpha, _HologramBlend; + half4 _HologramStripeColor; + + half _ChromAberrAmount, _ChromAberrAlpha; + + half _GlitchAmount, _GlitchSize, _GlitchSpeed; + + half _FlickerFreq, _FlickerPercent, _FlickerAlpha; + + half _ShadowX, _ShadowY, _ShadowAlpha; + half4 _ShadowColor; + + half4 _ShineColor; + half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow; + + half _AlphaCutoffValue; + + half _AlphaRoundThreshold; + + half4 _ColorChangeNewCol, _ColorChangeTarget; + half _ColorChangeTolerance, _ColorChangeLuminosity; + + half4 _ColorChangeNewCol2, _ColorChangeTarget2; + half _ColorChangeTolerance2; + + half4 _ColorChangeNewCol3, _ColorChangeTarget3; + half _ColorChangeTolerance3; + + half _Contrast, _Brightness; + + //half4 _OverlayTex_ST; + float4 _OverlayTex_ScaleAndTiling; + float4 _OverlayColor; + half _OverlayGlow, _OverlayBlend, _OverlayTextureScrollXSpeed, _OverlayTextureScrollYSpeed; + + float _RandomSeed; +CBUFFER_END + + +#define CUSTOM_TRANSFORM_TEX(uv, st) uv * st.xy + st.zw +#define GET_PIXEL(offsetX, offsetY, uv, tex, texelSize) SAMPLE_TEXTURE2D(tex, sampler##tex, uv + half2(offsetX * texelSize.x, offsetY * texelSize.y)).rgb +#define DECLARE_TEX_AND_SAMPLER(texName) \ + TEXTURE2D(texName);\ + SAMPLER(sampler##texName); + + +DECLARE_TEX_AND_SAMPLER(_MainTex) + +#if FADE_ON + DECLARE_TEX_AND_SAMPLER(_FadeTex) + DECLARE_TEX_AND_SAMPLER(_FadeBurnTex) +#endif + +#if GLOW_ON + DECLARE_TEX_AND_SAMPLER(_GlowTex) + //sampler2D _GlowTex; +#endif + +#if OUTTEX_ON + DECLARE_TEX_AND_SAMPLER(_OutlineTex) +#endif + +#if OUTDIST_ON + DECLARE_TEX_AND_SAMPLER(_OutlineDistortTex) + //sampler2D _OutlineDistortTex; +#endif + +#if DISTORT_ON + DECLARE_TEX_AND_SAMPLER(_DistortTex) + //sampler2D _DistortTex; +#endif + +#if COLORSWAP_ON + DECLARE_TEX_AND_SAMPLER(_ColorSwapTex) +#endif + +#if COLORRAMP_ON + DECLARE_TEX_AND_SAMPLER(_ColorRampTex) + DECLARE_TEX_AND_SAMPLER(_ColorRampTexGradient) +#endif + +#if SHINE_ON + DECLARE_TEX_AND_SAMPLER(_ShineMask) +#endif + +#if OVERLAY_ON + DECLARE_TEX_AND_SAMPLER(_OverlayTex) +#endif + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Properties.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Properties.hlsl.meta new file mode 100644 index 0000000..3bf71af --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Properties.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 8b6109d96c9d070479a709f48fb8ccce +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Properties.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_ShaderFeatures.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_ShaderFeatures.hlsl new file mode 100644 index 0000000..371846a --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_ShaderFeatures.hlsl @@ -0,0 +1,76 @@ +#ifndef ALLIN1SPRITESHADERSRP_SHADERFEATURES +#define ALLIN1SPRITESHADERSRP_SHADERFEATURES + +#pragma shader_feature_local GLOW_ON +#pragma shader_feature_local FADE_ON +#pragma shader_feature_local OUTBASE_ON +#pragma shader_feature_local ONLYOUTLINE_ON +#pragma shader_feature_local GRADIENT_ON +#pragma shader_feature_local GRADIENT2COL_ON +#pragma shader_feature_local RADIALGRADIENT_ON +#pragma shader_feature_local COLORSWAP_ON +#pragma shader_feature_local HSV_ON +#pragma shader_feature_local CHANGECOLOR_ON +#pragma shader_feature_local CHANGECOLOR2_ON +#pragma shader_feature_local CHANGECOLOR3_ON +#pragma shader_feature_local COLORRAMP_ON +#pragma shader_feature_local GRADIENTCOLORRAMP_ON +#pragma shader_feature_local HITEFFECT_ON +#pragma shader_feature_local NEGATIVE_ON +#pragma shader_feature_local PIXELATE_ON +#pragma shader_feature_local GREYSCALE_ON +#pragma shader_feature_local POSTERIZE_ON +#pragma shader_feature_local BLUR_ON +#pragma shader_feature_local MOTIONBLUR_ON +#pragma shader_feature_local GHOST_ON +#pragma shader_feature_local ALPHAOUTLINE_ON +#pragma shader_feature_local INNEROUTLINE_ON +#pragma shader_feature_local ONLYINNEROUTLINE_ON +#pragma shader_feature_local HOLOGRAM_ON +#pragma shader_feature_local CHROMABERR_ON +#pragma shader_feature_local GLITCH_ON +#pragma shader_feature_local FLICKER_ON +#pragma shader_feature_local SHADOW_ON +#pragma shader_feature_local SHINE_ON +#pragma shader_feature_local CONTRAST_ON +#pragma shader_feature_local OVERLAY_ON +#pragma shader_feature_local OVERLAYMULT_ON +#pragma shader_feature_local ALPHACUTOFF_ON +#pragma shader_feature_local ALPHAROUND_ON +#pragma shader_feature_local DOODLE_ON +#pragma shader_feature_local WIND_ON +#pragma shader_feature_local WAVEUV_ON +#pragma shader_feature_local ROUNDWAVEUV_ON +#pragma shader_feature_local RECTSIZE_ON +#pragma shader_feature_local OFFSETUV_ON +#pragma shader_feature_local CLIPPING_ON +#pragma shader_feature_local RADIALCLIPPING_ON +#pragma shader_feature_local TEXTURESCROLL_ON +#pragma shader_feature_local ZOOMUV_ON +#pragma shader_feature_local DISTORT_ON +#pragma shader_feature_local WARP_ON +#pragma shader_feature_local TWISTUV_ON +#pragma shader_feature_local ROTATEUV_ON +#pragma shader_feature_local POLARUV_ON +#pragma shader_feature_local FISHEYE_ON +#pragma shader_feature_local PINCH_ON +#pragma shader_feature_local SHAKEUV_ON + +#pragma shader_feature_local GLOWTEX_ON +#pragma shader_feature_local OUTTEX_ON +#pragma shader_feature_local OUTDIST_ON +#pragma shader_feature_local OUTBASE8DIR_ON +#pragma shader_feature_local OUTBASEPIXELPERF_ON +#pragma shader_feature_local COLORRAMPOUTLINE_ON +#pragma shader_feature_local GREYSCALEOUTLINE_ON +#pragma shader_feature_local POSTERIZEOUTLINE_ON +#pragma shader_feature_local BLURISHD_ON +#pragma shader_feature_local MANUALWIND_ON +#pragma shader_feature ATLAS_ON +#pragma shader_feature PREMULTIPLYALPHA_ON + +#pragma shader_feature BILBOARD_ON +#pragma shader_feature BILBOARDY_ON +#pragma shader_feature FOG_ON + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_ShaderFeatures.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_ShaderFeatures.hlsl.meta new file mode 100644 index 0000000..6e3b163 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_ShaderFeatures.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: fb77b0e21e6914b448db01edf0081e34 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_ShaderFeatures.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Structs.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Structs.hlsl new file mode 100644 index 0000000..be71582 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Structs.hlsl @@ -0,0 +1,40 @@ +#ifndef ALLIN1SPRITESHADERSRP_STRUCTS +#define ALLIN1SPRITESHADERSRP_STRUCTS + +struct appdata +{ + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + half4 color : COLOR; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct v2f +{ + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + half4 color : COLOR; + +#if OUTTEX_ON + half2 uvOutTex : TEXCOORD1; +#endif + +#if OUTDIST_ON + half2 uvOutDistTex : TEXCOORD2; +#endif + +#if DISTORT_ON + half2 uvDistTex : TEXCOORD3; +#endif + +#if FOG_ON + float fogCoord : TEXCOORD4; +#endif + + float3 positionWS : TEXCOORD5; + + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO +}; + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Structs.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Structs.hlsl.meta new file mode 100644 index 0000000..a4b3e11 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Structs.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 90c9bb4f3a943e54ab9fe837a2ffe287 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_Structs.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_URPHelper.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_URPHelper.hlsl new file mode 100644 index 0000000..e5c7492 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_URPHelper.hlsl @@ -0,0 +1,14 @@ +#ifndef ALLIN1SPRITESHADERSRP_URPHELPER +#define ALLIN1SPRITESHADERSRP_URPHELPER + +//clipPos and positionWS only used in HDRP. They're here to make both functions have the same parameters +float4 AllIn1MixFog(float4 inputColor, float4 clipPos, float3 positionWS, float fogCoord) +{ + float4 res = inputColor; + + res.rgb = MixFog(inputColor.rgb, fogCoord); + + return res; +} + +#endif //ALLIN1SPRITESHADERSRP_URPHELPER \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_URPHelper.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_URPHelper.hlsl.meta new file mode 100644 index 0000000..8ce4c33 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_URPHelper.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 27824951bd98b3140ba8ba40179436c4 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_URPHelper.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_VertexPass.hlsl b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_VertexPass.hlsl new file mode 100644 index 0000000..17397bb --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_VertexPass.hlsl @@ -0,0 +1,81 @@ +#ifndef ALLIN1SPRITESHADERSRP_VERTEXPASS +#define ALLIN1SPRITESHADERSRP_VERTEXPASS + +v2f vert(appdata v) +{ + #if RECTSIZE_ON + v.vertex.xyz += (v.vertex.xyz * (_RectSize - 1.0)); + #endif + + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_TRANSFER_INSTANCE_ID(v, o); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + #if BILBOARD_ON + half3 camRight = mul((half3x3)unity_CameraToWorld, half3(1,0,0)); + half3 camUp = half3(0,1,0); + #if BILBOARDY_ON + camUp = mul((half3x3)unity_CameraToWorld, half3(0,1,0)); + #endif + half3 localPos = v.vertex.x * camRight + v.vertex.y * camUp; + + #if UNITY_VERSION >= 60000000 + localPos.xy *= unity_SpriteProps.xy; + #endif + o.vertex = TransformObjectToHClip(half4(localPos, 1).xyz); + #else + half3 localPos = v.vertex.xyz; + #if UNITY_VERSION >= 60000000 && !defined(HDRP_PASS) + localPos.xy *= unity_SpriteProps.xy; + #endif + o.vertex = TransformObjectToHClip(localPos); + #endif + o.uv = /*TRANSFORM_TEX(v.uv, _MainTex)*/v.uv * _MainTex_ScaleAndTiling.xy + _MainTex_ScaleAndTiling.zw; + o.color = v.color; + + half2 center = half2(0.5, 0.5); + #if ATLAS_ON + center = half2((_MaxXUV + _MinXUV) / 2.0, (_MaxYUV + _MinYUV) / 2.0); + #endif + + #if POLARUV_ON + o.uv = v.uv - center; + #endif + + #if ROTATEUV_ON + half2 uvC = v.uv; + half cosAngle = cos(_RotateUvAmount); + half sinAngle = sin(_RotateUvAmount); + half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle); + uvC -= center; + o.uv = mul(rot, uvC); + o.uv += center; + #endif + + #if OUTTEX_ON + o.uvOutTex = CUSTOM_TRANSFORM_TEX(v.uv, _OutlineTex_ScaleAndTiling); + #endif + + #if OUTDIST_ON + o.uvOutDistTex = CUSTOM_TRANSFORM_TEX(v.uv, _OutlineDistortTex_ScaleAndTiling); + #endif + + #if DISTORT_ON + o.uvDistTex = CUSTOM_TRANSFORM_TEX(v.uv, _DistortTex_ScaleAndTiling); + #endif + + #if FOG_ON + o.fogCoord = 0; + #if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2) + o.fogCoord = ComputeFogFactor(o.vertex.z); + #endif + #endif + + o.positionWS = TransformObjectToWorld(v.vertex.xyz); + + + return o; +} + +#endif \ No newline at end of file diff --git a/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_VertexPass.hlsl.meta b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_VertexPass.hlsl.meta new file mode 100644 index 0000000..eed60db --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_VertexPass.hlsl.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 5b28c43114df6394c8e01e077af6cae9 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Shaders/ShaderLibrary/AllIn1SpriteShaderSRP_VertexPass.hlsl + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures.meta b/Assets/Plugins/AllIn1SpriteShader/Textures.meta new file mode 100644 index 0000000..3b81dbc --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9c6641ac06ac9d643898c55a675118f8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures.meta new file mode 100644 index 0000000..1cadac3 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5dc994715c67a694eafe9d1fba38560d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_1.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_1.png new file mode 100644 index 0000000..01d510d Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_1.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_1.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_1.png.meta new file mode 100644 index 0000000..804e6f5 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_1.png.meta @@ -0,0 +1,95 @@ +fileFormatVersion: 2 +guid: 7062336ff4b66994caa2ba23c8651342 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 6534a81033212394099b1c2e60060263 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_1.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_2.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_2.png new file mode 100644 index 0000000..f925cc5 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_2.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_2.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_2.png.meta new file mode 100644 index 0000000..8956628 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_2.png.meta @@ -0,0 +1,95 @@ +fileFormatVersion: 2 +guid: 2eb26501acf862843a55a2e79af0c3c8 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: b49496914e94fc94f80d6b9197ecf935 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/gradientTexture_2.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-bumbleberry.psd b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-bumbleberry.psd new file mode 100644 index 0000000..266704b Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-bumbleberry.psd differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-bumbleberry.psd.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-bumbleberry.psd.meta new file mode 100644 index 0000000..2c8c62a --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-bumbleberry.psd.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: a9058d3dd9b9dd14cbc6b16db7859653 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 6b5fce476d6279846b6aee1cf9447c38 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 1 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-bumbleberry.psd + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-cool.psd b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-cool.psd new file mode 100644 index 0000000..17ab124 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-cool.psd differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-cool.psd.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-cool.psd.meta new file mode 100644 index 0000000..623a035 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-cool.psd.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: bf981ecbfe649344eafdbc788f6dab0f +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: c61c2ea72b408804c90e310880261312 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 1 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-cool.psd + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-downwell.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-downwell.png new file mode 100644 index 0000000..3c108ba Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-downwell.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-downwell.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-downwell.png.meta new file mode 100644 index 0000000..ae5f20a --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-downwell.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 279657edc397ece4b8029c727adf6ddc +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 85966af9cdddb7d4bbd347c94e844740 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-downwell.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-earthy.psd b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-earthy.psd new file mode 100644 index 0000000..e302149 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-earthy.psd differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-earthy.psd.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-earthy.psd.meta new file mode 100644 index 0000000..b3383dc --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-earthy.psd.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: b3cfc9bf16a1cfa4ab153965dff63ad3 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: f38908602dd238b409bc43bb9953646d + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 1 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-earthy.psd + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy-pop-1x.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy-pop-1x.png new file mode 100644 index 0000000..d98dd2d Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy-pop-1x.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy-pop-1x.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy-pop-1x.png.meta new file mode 100644 index 0000000..fd99875 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy-pop-1x.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 763e13699209a614b8800c76fc9dee48 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 4acacabd6b7da7644a38538f7ac969fa + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy-pop-1x.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy.psd b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy.psd new file mode 100644 index 0000000..9daeca3 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy.psd differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy.psd.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy.psd.meta new file mode 100644 index 0000000..ad18791 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy.psd.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 285a35f6ccf7b1a44b6c198e96105173 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 45d692c8481a23a4ca4bf338eb345b89 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 1 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-gameboy.psd + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-metroid-ii-sgb-1x.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-metroid-ii-sgb-1x.png new file mode 100644 index 0000000..4b94e7a Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-metroid-ii-sgb-1x.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-metroid-ii-sgb-1x.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-metroid-ii-sgb-1x.png.meta new file mode 100644 index 0000000..0809647 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-metroid-ii-sgb-1x.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 54b37de4aa07caa4797254cf2351058f +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: fdaff416f4292e748acd0edc2ccd3a1b + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-metroid-ii-sgb-1x.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-mist-gb-1x.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-mist-gb-1x.png new file mode 100644 index 0000000..432a586 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-mist-gb-1x.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-mist-gb-1x.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-mist-gb-1x.png.meta new file mode 100644 index 0000000..56f56b0 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-mist-gb-1x.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 359431ef2af87794198688f7c632c1e3 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: c8412b3bf254b83478e63d50248d9511 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-mist-gb-1x.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-neapolitan.psd b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-neapolitan.psd new file mode 100644 index 0000000..07d74a3 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-neapolitan.psd differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-neapolitan.psd.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-neapolitan.psd.meta new file mode 100644 index 0000000..7de51b9 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-neapolitan.psd.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: cbb1819678c0e5a4c82464e4b1c0ce1c +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: bbc95717f5bfe2342801eb1509f0c21e + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 1 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-neapolitan.psd + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-bgb-1x.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-bgb-1x.png new file mode 100644 index 0000000..f7b9554 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-bgb-1x.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-bgb-1x.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-bgb-1x.png.meta new file mode 100644 index 0000000..42acac6 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-bgb-1x.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 8700b580d2f74da46b4cbcb5fde72d63 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 8bac87bbb6aabc449b1dbd4f1da1819f + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-bgb-1x.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-black-zero-1x.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-black-zero-1x.png new file mode 100644 index 0000000..dc91c10 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-black-zero-1x.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-black-zero-1x.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-black-zero-1x.png.meta new file mode 100644 index 0000000..5d12dbe --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-black-zero-1x.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 2a39734b8956da843adee1646c75554f +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 9deeee28a79225f4fb4d99a97a42b3ea + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-nintendo-gameboy-black-zero-1x.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-platinum-1x.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-platinum-1x.png new file mode 100644 index 0000000..0ca0255 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-platinum-1x.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-platinum-1x.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-platinum-1x.png.meta new file mode 100644 index 0000000..710f6ef --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-platinum-1x.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 6fc6eee88963e63429ed61892dadd042 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5a250b7cef21ca84d8fc79970b91cc65 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/palette-platinum-1x.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/shadeRamp.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/shadeRamp.png new file mode 100644 index 0000000..d9dc310 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/shadeRamp.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/shadeRamp.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/shadeRamp.png.meta new file mode 100644 index 0000000..58c0b2d --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/shadeRamp.png.meta @@ -0,0 +1,95 @@ +fileFormatVersion: 2 +guid: 555ec36b8c5401649af750d9738c7ddf +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 592402d35dab4094da345853c417524b + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/shadeRamp.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/toonShadeRamp.png b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/toonShadeRamp.png new file mode 100644 index 0000000..482d4a4 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/toonShadeRamp.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/toonShadeRamp.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/toonShadeRamp.png.meta new file mode 100644 index 0000000..9a3e282 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/toonShadeRamp.png.meta @@ -0,0 +1,95 @@ +fileFormatVersion: 2 +guid: 536abb94c423a3443b5151f665cdc017 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: f37da52049ecfd04eb6a0a5176418ac1 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/GradientTextures/toonShadeRamp.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/NormalMaps.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/NormalMaps.meta new file mode 100644 index 0000000..8a05722 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/NormalMaps.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c509d09ace1b4f84da7401dc3c5616a3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/NormalMaps/spaceSoldierNormalMap.png b/Assets/Plugins/AllIn1SpriteShader/Textures/NormalMaps/spaceSoldierNormalMap.png new file mode 100644 index 0000000..09c3581 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/NormalMaps/spaceSoldierNormalMap.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/NormalMaps/spaceSoldierNormalMap.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/NormalMaps/spaceSoldierNormalMap.png.meta new file mode 100644 index 0000000..ff7ba61 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/NormalMaps/spaceSoldierNormalMap.png.meta @@ -0,0 +1,95 @@ +fileFormatVersion: 2 +guid: 115ee11beb34a5247bc5bd53377a08f2 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 1 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 04a63e1d3a18ab9419ae1e2e245ef80a + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/NormalMaps/spaceSoldierNormalMap.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/UVChecker.png b/Assets/Plugins/AllIn1SpriteShader/Textures/UVChecker.png new file mode 100644 index 0000000..e5ae774 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/UVChecker.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/UVChecker.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/UVChecker.png.meta new file mode 100644 index 0000000..41ed17b --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/UVChecker.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: a4a73598226c9dd48aedc26a44264bdf +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 0 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 32 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 49b78288c6606b142947c3702972ad14 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/UVChecker.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/black.png b/Assets/Plugins/AllIn1SpriteShader/Textures/black.png new file mode 100644 index 0000000..72d8393 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/black.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/black.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/black.png.meta new file mode 100644 index 0000000..c641617 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/black.png.meta @@ -0,0 +1,95 @@ +fileFormatVersion: 2 +guid: 0b8da974a6429b8489e21c2a5d8dd509 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: f397292dae7cff94fa11946d513d2c05 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/black.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/fire.png b/Assets/Plugins/AllIn1SpriteShader/Textures/fire.png new file mode 100644 index 0000000..b58d434 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/fire.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/fire.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/fire.png.meta new file mode 100644 index 0000000..616e465 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/fire.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 253ade5030af1b643bf9a54cceb26f01 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 0 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 512 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 512 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 512 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 87af0f70de267414287ea2f131be64a9 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/fire.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/fire2.png b/Assets/Plugins/AllIn1SpriteShader/Textures/fire2.png new file mode 100644 index 0000000..6f97d82 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/fire2.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/fire2.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/fire2.png.meta new file mode 100644 index 0000000..752f2c6 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/fire2.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 677cca399782dea41aedc1d292ecb67d +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 0 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 512 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 512 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 512 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 164c93aa3c349884aab20273f4e027ed + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/fire2.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise.png b/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise.png new file mode 100644 index 0000000..d2078ef Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise.png.meta new file mode 100644 index 0000000..cbfc6c5 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 806e236bc12668e4da974bb8f536d28f +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 0 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 00ad019334681ad4e94f90f4e6870ade + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise2.png b/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise2.png new file mode 100644 index 0000000..de6a4f8 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise2.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise2.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise2.png.meta new file mode 100644 index 0000000..8299b0e --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise2.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: e3763a0fd85c67f4f9f31b55f886d31d +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 0 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: df4dc4f6bf59b0046b0f0b70b9c13a19 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/flameNoise2.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/gradient.png b/Assets/Plugins/AllIn1SpriteShader/Textures/gradient.png new file mode 100644 index 0000000..b9b4c0a Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/gradient.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/gradient.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/gradient.png.meta new file mode 100644 index 0000000..002ad2a --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/gradient.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: b2ae57e82cd4b4d4ebfa9986f7c77c83 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 0 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: e7046a03f726c4e48b86b2beaa92795d + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/gradient.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/gradient2.png b/Assets/Plugins/AllIn1SpriteShader/Textures/gradient2.png new file mode 100644 index 0000000..8e3e92f Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/gradient2.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/gradient2.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/gradient2.png.meta new file mode 100644 index 0000000..fc1395c --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/gradient2.png.meta @@ -0,0 +1,117 @@ +fileFormatVersion: 2 +guid: dbaa905cec0d2b944b5d1ebdbc3ceb1e +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: fe5dc1f04fb78b54aab6a687e244d6d7 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/gradient2.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/rainbow.png b/Assets/Plugins/AllIn1SpriteShader/Textures/rainbow.png new file mode 100644 index 0000000..6dc1b23 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/rainbow.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/rainbow.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/rainbow.png.meta new file mode 100644 index 0000000..371d394 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/rainbow.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 74087f6d03f233e4a8a142fa01f9e5cf +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 0 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: adace43c9876fa64fb0fa83de503839c + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/rainbow.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/seamlessNoise.png b/Assets/Plugins/AllIn1SpriteShader/Textures/seamlessNoise.png new file mode 100644 index 0000000..6b9b495 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/seamlessNoise.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/seamlessNoise.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/seamlessNoise.png.meta new file mode 100644 index 0000000..27a6a49 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/seamlessNoise.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: 7aad8c583ef292e48b06af0d1f2fab97 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 0 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 50 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 59e65a015812bfd44aabe97ca2ef2ca1 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/seamlessNoise.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/toonSeamlessNoise.png b/Assets/Plugins/AllIn1SpriteShader/Textures/toonSeamlessNoise.png new file mode 100644 index 0000000..8211cb6 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/toonSeamlessNoise.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/toonSeamlessNoise.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/toonSeamlessNoise.png.meta new file mode 100644 index 0000000..d56ce96 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/toonSeamlessNoise.png.meta @@ -0,0 +1,139 @@ +fileFormatVersion: 2 +guid: f96aebb9bcd1e3b44bafbb23b1bdac88 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 0 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 256 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: c347a607987f5654397113952ea0e2bd + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/toonSeamlessNoise.png + uploadId: 857600 diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/white.png b/Assets/Plugins/AllIn1SpriteShader/Textures/white.png new file mode 100644 index 0000000..944b045 Binary files /dev/null and b/Assets/Plugins/AllIn1SpriteShader/Textures/white.png differ diff --git a/Assets/Plugins/AllIn1SpriteShader/Textures/white.png.meta b/Assets/Plugins/AllIn1SpriteShader/Textures/white.png.meta new file mode 100644 index 0000000..c9f4553 --- /dev/null +++ b/Assets/Plugins/AllIn1SpriteShader/Textures/white.png.meta @@ -0,0 +1,95 @@ +fileFormatVersion: 2 +guid: 839adabbc5de26041bac66450214a831 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 407e6d8edc94c6b4a9325118700cfe09 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: +AssetOrigin: + serializedVersion: 1 + productId: 156513 + packageName: All In 1 Sprite Shader + packageVersion: 4.661 + assetPath: Assets/Plugins/AllIn1SpriteShader/Textures/white.png + uploadId: 857600 diff --git a/Assets/Settings/Mobile_RPAsset.asset b/Assets/Settings/Mobile_RPAsset.asset index 7ceffe7..fedee07 100644 --- a/Assets/Settings/Mobile_RPAsset.asset +++ b/Assets/Settings/Mobile_RPAsset.asset @@ -12,8 +12,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: bf2edee5c58d82540a51f03df9d42094, type: 3} m_Name: Mobile_RPAsset m_EditorClassIdentifier: - k_AssetVersion: 12 - k_AssetPreviousVersion: 12 + k_AssetVersion: 13 + k_AssetPreviousVersion: 13 m_RendererType: 1 m_RendererData: {fileID: 0} m_RendererDataList: @@ -53,6 +53,7 @@ MonoBehaviour: m_AdditionalLightsShadowResolutionTierHigh: 1024 m_ReflectionProbeBlending: 1 m_ReflectionProbeBoxProjection: 1 + m_ReflectionProbeAtlas: 1 m_ShadowDistance: 50 m_ShadowCascadeCount: 1 m_Cascade2Split: 0.25 @@ -78,11 +79,11 @@ MonoBehaviour: m_UseAdaptivePerformance: 1 m_ColorGradingMode: 0 m_ColorGradingLutSize: 32 + m_AllowPostProcessAlphaOutput: 0 m_UseFastSRGBLinearConversion: 1 m_SupportDataDrivenLensFlare: 1 m_SupportScreenSpaceLensFlare: 1 m_GPUResidentDrawerMode: 0 - m_UseLegacyLightmaps: 0 m_SmallMeshScreenPercentage: 0 m_GPUResidentDrawerEnableOcclusionCullingInCameras: 0 m_ShadowType: 1 @@ -109,6 +110,7 @@ MonoBehaviour: m_PrefilterDebugKeywords: 1 m_PrefilterWriteRenderingLayers: 1 m_PrefilterHDROutput: 1 + m_PrefilterAlphaOutput: 0 m_PrefilterSSAODepthNormals: 1 m_PrefilterSSAOSourceDepthLow: 1 m_PrefilterSSAOSourceDepthMedium: 0 @@ -126,8 +128,14 @@ MonoBehaviour: m_PrefilterSoftShadowsQualityHigh: 1 m_PrefilterSoftShadows: 0 m_PrefilterScreenCoord: 1 + m_PrefilterScreenSpaceIrradiance: 0 m_PrefilterNativeRenderPass: 1 m_PrefilterUseLegacyLightmaps: 0 + m_PrefilterBicubicLightmapSampling: 0 + m_PrefilterReflectionProbeRotation: 0 + m_PrefilterReflectionProbeBlending: 0 + m_PrefilterReflectionProbeBoxProjection: 0 + m_PrefilterReflectionProbeAtlas: 0 m_ShaderVariantLogLevel: 0 m_ShadowCascades: 0 m_Textures: diff --git a/Assets/Settings/PC_Renderer.asset b/Assets/Settings/PC_Renderer.asset index 475b02e..e70caf9 100644 --- a/Assets/Settings/PC_Renderer.asset +++ b/Assets/Settings/PC_Renderer.asset @@ -1,5 +1,91 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!114 &-8129348755968261619 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b3d386ba5cd94485973aee1479b272e, type: 3} + m_Name: Render Feature - Outline Transparent + m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Runtime::UnityEngine.Rendering.Universal.RenderObjects + m_Active: 1 + settings: + passTag: RenderObjectsFeature + Event: 500 + filterSettings: + RenderQueueType: 1 + LayerMask: + serializedVersion: 2 + m_Bits: 4294967295 + PassNames: + - OutlinePass + overrideMaterial: {fileID: 0} + overrideMaterialPassIndex: 0 + overrideShader: {fileID: 0} + overrideShaderPassIndex: 0 + overrideMode: 1 + overrideDepthState: 0 + depthCompareFunction: 4 + enableWrite: 1 + stencilSettings: + overrideStencilState: 0 + stencilReference: 0 + stencilCompareFunction: 8 + passOperation: 0 + failOperation: 0 + zFailOperation: 0 + cameraSettings: + overrideCamera: 0 + restoreCamera: 1 + offset: {x: 0, y: 0, z: 0, w: 0} + cameraFieldOfView: 60 +--- !u!114 &-7126798952212071218 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b3d386ba5cd94485973aee1479b272e, type: 3} + m_Name: Render Feature - Outline Opaque + m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Runtime::UnityEngine.Rendering.Universal.RenderObjects + m_Active: 1 + settings: + passTag: RenderObjectsFeature + Event: 300 + filterSettings: + RenderQueueType: 0 + LayerMask: + serializedVersion: 2 + m_Bits: 4294967295 + PassNames: + - OutlinePass + overrideMaterial: {fileID: 0} + overrideMaterialPassIndex: 0 + overrideShader: {fileID: 0} + overrideShaderPassIndex: 0 + overrideMode: 1 + overrideDepthState: 0 + depthCompareFunction: 4 + enableWrite: 1 + stencilSettings: + overrideStencilState: 0 + stencilReference: 0 + stencilCompareFunction: 8 + passOperation: 0 + failOperation: 0 + zFailOperation: 0 + cameraSettings: + overrideCamera: 0 + restoreCamera: 1 + offset: {x: 0, y: 0, z: 0, w: 0} + cameraFieldOfView: 60 --- !u!114 &11400000 MonoBehaviour: m_ObjectHideFlags: 0 @@ -13,32 +99,29 @@ MonoBehaviour: m_Name: PC_Renderer m_EditorClassIdentifier: debugShaders: - debugReplacementPS: {fileID: 4800000, guid: cf852408f2e174538bcd9b7fda1c5ae7, - type: 3} + debugReplacementPS: {fileID: 4800000, guid: cf852408f2e174538bcd9b7fda1c5ae7, type: 3} hdrDebugViewPS: {fileID: 4800000, guid: 573620ae32aec764abd4d728906d2587, type: 3} - probeVolumeSamplingDebugComputeShader: {fileID: 7200000, guid: 53626a513ea68ce47b59dc1299fe3959, - type: 3} + probeVolumeSamplingDebugComputeShader: {fileID: 7200000, guid: 53626a513ea68ce47b59dc1299fe3959, type: 3} probeVolumeResources: - probeVolumeDebugShader: {fileID: 4800000, guid: e5c6678ed2aaa91408dd3df699057aae, - type: 3} - probeVolumeFragmentationDebugShader: {fileID: 4800000, guid: 03cfc4915c15d504a9ed85ecc404e607, - type: 3} - probeVolumeOffsetDebugShader: {fileID: 4800000, guid: 53a11f4ebaebf4049b3638ef78dc9664, - type: 3} - probeVolumeSamplingDebugShader: {fileID: 4800000, guid: 8f96cd657dc40064aa21efcc7e50a2e7, - type: 3} - probeSamplingDebugMesh: {fileID: -3555484719484374845, guid: 57d7c4c16e2765b47a4d2069b311bffe, - type: 3} - probeSamplingDebugTexture: {fileID: 2800000, guid: 24ec0e140fb444a44ab96ee80844e18e, - type: 3} - probeVolumeBlendStatesCS: {fileID: 7200000, guid: b9a23f869c4fd45f19c5ada54dd82176, - type: 3} + probeVolumeDebugShader: {fileID: 4800000, guid: e5c6678ed2aaa91408dd3df699057aae, type: 3} + probeVolumeFragmentationDebugShader: {fileID: 4800000, guid: 03cfc4915c15d504a9ed85ecc404e607, type: 3} + probeVolumeOffsetDebugShader: {fileID: 4800000, guid: 53a11f4ebaebf4049b3638ef78dc9664, type: 3} + probeVolumeSamplingDebugShader: {fileID: 4800000, guid: 8f96cd657dc40064aa21efcc7e50a2e7, type: 3} + probeSamplingDebugMesh: {fileID: -3555484719484374845, guid: 57d7c4c16e2765b47a4d2069b311bffe, type: 3} + probeSamplingDebugTexture: {fileID: 2800000, guid: 24ec0e140fb444a44ab96ee80844e18e, type: 3} + probeVolumeBlendStatesCS: {fileID: 7200000, guid: b9a23f869c4fd45f19c5ada54dd82176, type: 3} m_RendererFeatures: - {fileID: 7833122117494664109} - m_RendererFeatureMap: ad6b866f10d7b46c + - {fileID: -7126798952212071218} + - {fileID: -8129348755968261619} + m_RendererFeatureMap: ad6b866f10d7b46c00000000000000000000000000000000 m_UseNativeRenderPass: 1 + xrSystemData: {fileID: 0} postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2} - m_AssetVersion: 2 + m_AssetVersion: 3 + m_PrepassLayerMask: + serializedVersion: 2 + m_Bits: 4294967295 m_OpaqueLayerMask: serializedVersion: 2 m_Bits: 4294967295 @@ -56,6 +139,8 @@ MonoBehaviour: m_RenderingMode: 2 m_DepthPrimingMode: 0 m_CopyDepthMode: 0 + m_DepthAttachmentFormat: 0 + m_DepthTextureFormat: 0 m_AccurateGbufferNormals: 0 m_IntermediateTextureMode: 0 --- !u!114 &7833122117494664109 @@ -84,12 +169,3 @@ MonoBehaviour: BlurQuality: 0 Falloff: 100 SampleCount: -1 - m_BlueNoise256Textures: - - {fileID: 2800000, guid: 36f118343fc974119bee3d09e2111500, type: 3} - - {fileID: 2800000, guid: 4b7b083e6b6734e8bb2838b0b50a0bc8, type: 3} - - {fileID: 2800000, guid: c06cc21c692f94f5fb5206247191eeee, type: 3} - - {fileID: 2800000, guid: cb76dd40fa7654f9587f6a344f125c9a, type: 3} - - {fileID: 2800000, guid: e32226222ff144b24bf3a5a451de54bc, type: 3} - - {fileID: 2800000, guid: 3302065f671a8450b82c9ddf07426f3a, type: 3} - - {fileID: 2800000, guid: 56a77a3e8d64f47b6afe9e3c95cb57d5, type: 3} - m_Shader: {fileID: 4800000, guid: 0849e84e3d62649e8882e9d6f056a017, type: 3} diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index c24d7e7..4510a88 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -825,7 +825,8 @@ PlayerSettings: webGLCloseOnQuit: 0 webWasm2023: 0 webEnableSubmoduleStrippingCompatibility: 0 - scriptingDefineSymbols: {} + scriptingDefineSymbols: + Standalone: ALLIN13DSHADER_URP additionalCompilerArguments: {} platformArchitecture: {} scriptingBackend: